user_access

Versions
4.6 – 5
user_access($string, $account = NULL)
6
user_access($string, $account = NULL, $reset = FALSE)
7
user_access($string, $account = NULL)

Determine whether the user has a given privilege.

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.

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.

▾ 130 functions call user_access()

aggregator_block in modules/aggregator.module
Implementation of hook_block().
aggregator_menu in modules/aggregator.module
Implementation of hook_menu().
aggregator_page_list_validate in modules/aggregator.module
archive_block in modules/archive.module
Implementation of hook_block().
archive_menu in modules/archive.module
Implementation of hook_menu().
block_admin_configure in modules/block.module
Menu callback; displays the block configuration form.
block_menu in modules/block.module
Implementation of hook_menu().
blogapi_blogger_edit_post in modules/blogapi.module
Blogging API callback. Modifies the specified blog node.
blogapi_blogger_new_post in modules/blogapi.module
Blogging API callback. Inserts a new blog post as a node.
blogapi_menu in modules/blogapi.module
blogapi_validate_user in modules/blogapi.module
Ensure that the given user has permission to edit a blog.
blog_access in modules/blog.module
Implementation of hook_access().
blog_block in modules/blog.module
Implementation of hook_block().
blog_menu in modules/blog.module
Implementation of hook_menu().
blog_page_user in modules/blog.module
Displays a Drupal page containing recent blog entries of a given user.
blog_user in modules/blog.module
Implementation of hook_user().
book_access in modules/book.module
Implementation of hook_access().
book_export_html in modules/book.module
This function is called by book_export() to generate HTML for export.
book_form in modules/book.module
Implementation of hook_form().
book_link in modules/book.module
Implementation of hook_link().
book_menu in modules/book.module
Implementation of hook_menu().
book_nodeapi in modules/book.module
Implementation of hook_nodeapi().
book_submit in modules/book.module
Implementation of hook_submit().
book_toc in modules/book.module
Returns an array of titles and nid entries of book pages in table of contents order.
comment_access in modules/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_block in modules/comment.module
Implementation of hook_block().
comment_configure in modules/comment.module
Menu callback; presents the comment settings page.
comment_form in modules/comment.module
comment_form_alter in modules/comment.module
comment_link in modules/comment.module
Implementation of hook_link().
comment_links in modules/comment.module
comment_menu in modules/comment.module
Implementation of hook_menu().
comment_render in modules/comment.module
comment_reply in modules/comment.module
comment_save in modules/comment.module
Accepts a submission of new or changed comment content.
contact_mail_user in modules/contact.module
Personal contact page.
contact_menu in modules/contact.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.module
Returns true if the user is allowed to access this format.
filter_formats in modules/filter.module
Retrieve a list of input formats.
filter_menu in modules/filter.module
Implementation of hook_menu().
forum_access in modules/forum.module
Implementation of hook_access().
forum_block in modules/forum.module
Implementation of hook_block().
forum_menu in modules/forum.module
Implementation of hook_menu().
help_menu in modules/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_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
Grant access to nodes.
locale_menu in modules/locale.module
Implementation of hook_menu().
menu_form_alter in modules/menu.module
Implementation of hook_form_alter(). Add menu item fields to the node form.
menu_menu in modules/menu.module
Implementation of hook_menu().
menu_nodeapi in modules/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.module
Determine whether the current user may perform the given operation on the specified node.
node_access_example_form_alter in developer/examples/node_access_example.module
Implementation of hook_form_alter().
node_access_example_node_grants in developer/examples/node_access_example.module
Implementation of hook_node_grants().
node_example_access in developer/examples/node_example.module
Implementation of hook_access().
node_example_menu in developer/examples/node_example.module
Implementation of hook_menu().
node_form_array in modules/node.module
Generate the node editing form array.
node_menu in modules/node.module
Implementation of hook_menu().
node_object_prepare in modules/node.module
node_revisions in modules/node.module
Menu callback for revisions related activities.
node_revision_delete in modules/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.module
Generate an overview table of older revisions of a node.
node_revision_revert in modules/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.module
Prepare node for save and allow modules to make changes.
node_validate in modules/node.module
Perform validation checks on the given node.
page_access in modules/page.module
Implementation of hook_access().
page_example_menu in developer/examples/page_example.module
Implementation of hook_menu().
page_menu in modules/page.module
Implementation of hook_menu().
path_admin_delete_confirm in modules/path.module
Menu callback; confirms deleting an URL alias
path_form_alter in modules/path.module
Implementation of hook_form_alter().
path_menu in modules/path.module
Implementation of hook_menu().
path_nodeapi in modules/path.module
Implementation of hook_nodeapi().
poll_access in modules/poll.module
Implementation of hook_access().
poll_block in modules/poll.module
Implementation of hook_block().
poll_form in modules/poll.module
Implementation of hook_form().
poll_insert in modules/poll.module
poll_load in modules/poll.module
Implementation of hook_load().
poll_menu in modules/poll.module
Implementation of hook_menu().
profile_block in modules/profile.module
Implementation of hook_block().
profile_browse in modules/profile.module
Menu callback; display a list of user information.
profile_form_profile in modules/profile.module
profile_menu in modules/profile.module
Implementation of hook_menu().
profile_validate_profile in modules/profile.module
profile_view_field in modules/profile.module
profile_view_profile in modules/profile.module
search_block in modules/search.module
Implementation of hook_block().
search_menu in modules/search.module
Implementation of hook_menu().
statistics_block in modules/statistics.module
Implementation of hook_block().
statistics_link in modules/statistics.module
Implementation of hook_link().
statistics_menu in modules/statistics.module
Implementation of hook_menu().
story_access in modules/story.module
Implementation of hook_access().
story_menu in modules/story.module
Implementation of hook_menu().
system_menu in modules/system.module
Implementation of hook_menu().
system_theme_select_form in modules/system.module
Returns a fieldset containing the theme select form.
taxonomy_menu in modules/taxonomy.module
Implementation of hook_menu().
theme_aggregator_block_item in modules/aggregator.module
Format an individual feed item for display in the block.
theme_aggregator_feed in modules/aggregator.module
Format a news feed.
theme_forum_display in modules/forum.module
Format the forum body.
theme_get_settings in includes/theme.inc
Retrieve an associative array containing the settings for a theme.
theme_username in includes/theme.inc
Format a username.
theme_user_picture in modules/user.module
tracker_menu in modules/tracker.module
Implementation of hook_menu().
tracker_track_user in modules/tracker.module
Menu callback. Prints a listing of active nodes on the site.
upload_file_download in modules/upload.module
upload_form_alter in modules/upload.module
upload_link in modules/upload.module
Implementation of hook_link().
upload_menu in modules/upload.module
Implementation of hook_menu().
upload_nodeapi in modules/upload.module
Implementation of hook_nodeapi().
user_block in modules/user.module
Implementation of hook_block().
user_edit in modules/user.module
user_edit_form in modules/user.module
user_edit_validate in modules/user.module
user_menu in modules/user.module
Implementation of hook_menu().
user_register in modules/user.module
user_register_submit in modules/user.module
user_search in modules/user.module
Implementation of hook_search().
user_view in modules/user.module
_aggregator_page_list in modules/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.module
Generate an SQL join clause for use in fetching a node listing.
_node_access_where_sql in modules/node.module
Generate an SQL where clause for use in fetching a node listing.
_upload_form in modules/upload.module
_upload_prepare in modules/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.module

Code

modules/user.module, line 335

<?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])) {
    $result = db_query("SELECT DISTINCT(p.perm) FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN (%s)", implode(',', array_keys($account->roles)));

    $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
 
 

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.