Community Documentation

user_access

5 user.module user_access($string, $account = NULL)
6 user.module user_access($string, $account = NULL, $reset = FALSE)
7 user.module user_access($string, $account = NULL)
8 user.module user_access($string, $account = NULL)

Determine whether the user has a given privilege.

Parameters

$string: The permission, such as "administer nodes", being checked for.

$account: (optional) The account to check, if not given use currently logged in user.

Return value

boolean TRUE if the current user has the requested permission.

All permission checks in Drupal should go through this function. This way, we guarantee consistent behavior, and ensure that the superuser can perform all actions.

▾ 133 functions call user_access()

aggregator_block in modules/aggregator/aggregator.module
Implementation of hook_block().
aggregator_menu in modules/aggregator/aggregator.module
Implementation of hook_menu().
aggregator_page_list_validate in modules/aggregator/aggregator.module
block_admin_configure in modules/block/block.module
Menu callback; displays the block configuration form.
block_menu in modules/block/block.module
Implementation of hook_menu().
blogapi_blogger_edit_post in modules/blogapi/blogapi.module
Blogging API callback. Modifies the specified blog node.
blogapi_blogger_new_post in modules/blogapi/blogapi.module
Blogging API callback. Inserts a new blog post as a node.
blogapi_menu in modules/blogapi/blogapi.module
blogapi_mt_publish_post in modules/blogapi/blogapi.module
Blogging API callback. Publishes the given node
blogapi_status_error_check in modules/blogapi/blogapi.module
Check that the user has permission to save the node with the chosen status.
blogapi_validate_user in modules/blogapi/blogapi.module
Ensure that the given user has permission to edit a blog.
blog_access in modules/blog/blog.module
Implementation of hook_access().
blog_block in modules/blog/blog.module
Implementation of hook_block().
blog_menu in modules/blog/blog.module
Implementation of hook_menu().
blog_page_user in modules/blog/blog.module
Displays a Drupal page containing recent blog entries of a given user.
blog_user in modules/blog/blog.module
Implementation of hook_user().
book_access in modules/book/book.module
Implementation of hook_access().
book_export_html in modules/book/book.module
This function is called by book_export() to generate HTML for export.
book_form in modules/book/book.module
Implementation of hook_form().
book_link in modules/book/book.module
Implementation of hook_link().
book_menu in modules/book/book.module
Implementation of hook_menu().
book_submit in modules/book/book.module
Implementation of hook_submit().
book_toc in modules/book/book.module
Returns an array of titles and nid entries of book pages in table of contents order.
comment_access in modules/comment/comment.module
This is *not* a hook_access() implementation. This function is called to determine whether the current user has access to a particular comment.
comment_admin_settings in modules/comment/comment.module
Menu callback; presents the comment settings page.
comment_block in modules/comment/comment.module
Implementation of hook_block().
comment_form in modules/comment/comment.module
comment_form_alter in modules/comment/comment.module
comment_link in modules/comment/comment.module
Implementation of hook_link().
comment_links in modules/comment/comment.module
comment_menu in modules/comment/comment.module
Implementation of hook_menu().
comment_render in modules/comment/comment.module
Renders comment(s).
comment_reply in modules/comment/comment.module
This function is responsible for generating a comment reply form. There are several cases that have to be handled, including:
comment_save in modules/comment/comment.module
Accepts a submission of new or changed comment content.
contact_menu in modules/contact/contact.module
Implementation of hook_menu().
drupal_menu in modules/drupal/drupal.module
Implementation of hook_menu().
example_element_menu in developer/examples/example_element.module
Implementation of hook_menu().
fileupload_access in developer/examples/fileupload.module
Implementation of hook_access.
fileupload_file_download in developer/examples/fileupload.module
Implementation of hook_file_download.
fileupload_menu in developer/examples/fileupload.module
Implementation of hook_menu.
filter_access in modules/filter/filter.module
Returns TRUE if the user is allowed to access this format.
filter_formats in modules/filter/filter.module
Retrieve a list of input formats.
filter_menu in modules/filter/filter.module
Implementation of hook_menu().
forum_access in modules/forum/forum.module
Implementation of hook_access().
forum_block in modules/forum/forum.module
Implementation of hook_block().
forum_menu in modules/forum/forum.module
Implementation of hook_menu().
help_menu in modules/help/help.module
Implementation of hook_menu().
hook_access in developer/hooks/node.php
Define access restrictions.
hook_file_download in developer/hooks/core.php
Allow file downloads.
hook_link in developer/hooks/core.php
Define internal Drupal links.
hook_menu in developer/hooks/core.php
Define menu items and page callbacks.
hook_nodeapi in developer/hooks/core.php
Act on nodes defined by other modules.
hook_node_grants in developer/hooks/core.php
Inform the node access system what permissions the user has.
locale_menu in modules/locale/locale.module
Implementation of hook_menu().
menu_form_alter in modules/menu/menu.module
Implementation of hook_form_alter(). Add menu item fields to the node form.
menu_menu in modules/menu/menu.module
Implementation of hook_menu().
menu_nodeapi in modules/menu/menu.module
Implementation of hook_nodeapi().
menu_primary_links in includes/menu.inc
Returns an array containing the primary links. Can optionally descend from the root of the Primary links menu towards the current node for a specified number of levels and return that submenu. Used to generate a primary/secondary menu from different…
node_access in modules/node/node.module
Determine whether the current user may perform the given operation on the specified node.
node_access_example_node_grants in developer/examples/node_access_example.module
Implementation of hook_node_grants().
node_content_access in modules/node/node.module
Implementation of hook_access().
node_example_access in developer/examples/node_example.module
Implementation of hook_access().
node_form in modules/node/node.module
Generate the node add/edit form array.
node_form_alter in modules/node/node.module
Implementation of hook_form_alter().
node_menu in modules/node/node.module
Implementation of hook_menu().
node_revisions in modules/node/node.module
Menu callback for revisions related activities.
node_revision_delete in modules/node/node.module
Delete the revision with specified revision number. A "delete revision" nodeapi event is invoked when a revision is deleted.
node_revision_overview in modules/node/node.module
Generate an overview table of older revisions of a node.
node_revision_revert in modules/node/node.module
Revert to the revision with the specified revision number. A node and nodeapi "update" event is triggered (via the node_save() call) when a revision is reverted.
node_submit in modules/node/node.module
Prepare node for save and allow modules to make changes.
node_validate in modules/node/node.module
Perform validation checks on the given node.
page_example_menu in developer/examples/page_example.module
Implementation of hook_menu().
path_admin_delete_confirm in modules/path/path.module
Menu callback; confirms deleting an URL alias
path_form_alter in modules/path/path.module
Implementation of hook_form_alter().
path_menu in modules/path/path.module
Implementation of hook_menu().
path_nodeapi in modules/path/path.module
Implementation of hook_nodeapi().
poll_access in modules/poll/poll.module
Implementation of hook_access().
poll_block in modules/poll/poll.module
Implementation of hook_block().
poll_form in modules/poll/poll.module
Implementation of hook_form().
poll_insert in modules/poll/poll.module
poll_load in modules/poll/poll.module
Implementation of hook_load().
poll_menu in modules/poll/poll.module
Implementation of hook_menu().
profile_block in modules/profile/profile.module
Implementation of hook_block().
profile_browse in modules/profile/profile.module
Menu callback; display a list of user information.
profile_categories in modules/profile/profile.module
profile_menu in modules/profile/profile.module
Implementation of hook_menu().
profile_validate_profile in modules/profile/profile.module
profile_view_field in modules/profile/profile.module
profile_view_profile in modules/profile/profile.module
search_block in modules/search/search.module
Implementation of hook_block().
search_menu in modules/search/search.module
Implementation of hook_menu().
statistics_block in modules/statistics/statistics.module
Implementation of hook_block().
statistics_link in modules/statistics/statistics.module
Implementation of hook_link().
statistics_menu in modules/statistics/statistics.module
Implementation of hook_menu().
system_get_module_admin_tasks in modules/system/system.module
system_menu in modules/system/system.module
Implementation of hook_menu().
system_theme_select_form in modules/system/system.module
Returns a fieldset containing the theme select form.
taxonomy_menu in modules/taxonomy/taxonomy.module
Implementation of hook_menu().
theme_aggregator_block_item in modules/aggregator/aggregator.module
Format an individual feed item for display in the block.
theme_aggregator_feed in modules/aggregator/aggregator.module
Format a news feed.
theme_forum_display in modules/forum/forum.module
Format the forum body.
theme_get_settings in includes/theme.inc
Retrieve an associative array containing the settings for a theme.
theme_poll_results in modules/poll/poll.module
theme_username in includes/theme.inc
Format a username.
theme_user_picture in modules/user/user.module
throttle_menu in modules/throttle/throttle.module
tracker_menu in modules/tracker/tracker.module
Implementation of hook_menu().
tracker_track_user in modules/tracker/tracker.module
Menu callback. Prints a listing of active nodes on the site.
upload_file_download in modules/upload/upload.module
upload_form_alter in modules/upload/upload.module
upload_link in modules/upload/upload.module
Implementation of hook_link().
upload_menu in modules/upload/upload.module
Implementation of hook_menu().
upload_nodeapi in modules/upload/upload.module
Implementation of hook_nodeapi().
user_block in modules/user/user.module
Implementation of hook_block().
user_build_filter_query in modules/user/user.module
Build query for user administration filters based on session.
user_edit in modules/user/user.module
user_edit_form in modules/user/user.module
user_edit_validate in modules/user/user.module
user_menu in modules/user/user.module
Implementation of hook_menu().
user_register in modules/user/user.module
user_register_submit in modules/user/user.module
user_save in modules/user/user.module
Save changes to a user account or add a new user.
user_search in modules/user/user.module
Implementation of hook_search().
user_user_operations in modules/user/user.module
Implementation of hook_user_operations().
user_view in modules/user/user.module
_aggregator_page_list in modules/aggregator/aggregator.module
Prints an aggregator page listing a number of feed items. Various menu callbacks use this function to print their feeds.
_menu_site_is_offline in includes/menu.inc
Returns TRUE if the site is off-line for maintenance.
_node_access_join_sql in modules/node/node.module
Generate an SQL join clause for use in fetching a node listing.
_node_access_where_sql in modules/node/node.module
Generate an SQL where clause for use in fetching a node listing.
_profile_get_fields in modules/profile/profile.module
_upload_form in modules/upload/upload.module
_upload_prepare in modules/upload/upload.module
Save new uploads and attach them to the node object. append file_previews to the node object as well.
_user_edit_validate in modules/user/user.module

File

modules/user/user.module, line 361
Enables the user registration and login system.

Code

<?php
function user_access($string, $account = NULL) {
  global $user;
  static $perm = array();

  if (is_null($account)) {
    $account = $user;
  }

  // User #1 has all privileges:
  if ($account->uid == 1) {
    return TRUE;
  }

  // To reduce the number of SQL queries, we cache the user's permissions
  // in a static variable.
  if (!isset($perm[$account->uid])) {
    $rids = array_keys($account->roles);
    $placeholders = implode(',', array_fill(0, count($rids), '%d'));
    $result = db_query("SELECT DISTINCT(p.perm) FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN ($placeholders)", $rids);
    $perm[$account->uid] = '';
    while ($row = db_fetch_object($result)) {
      $perm[$account->uid] .= "$row->perm, ";
    }
  }

  if (isset($perm[$account->uid])) {
    return strpos($perm[$account->uid], "$string, ") !== FALSE;
  }

  return FALSE;
}
?>
Login or register to post comments