Same name and namespace in other branches
- 4.7.x developer/hooks/core.php \hook_user()
- 5.x developer/hooks/core.php \hook_user()
- 6.x developer/hooks/core.php \hook_user()
Act on user account actions.
This hook allows modules to react when operations are performed on user accounts.
Parameters
$op: What kind of action is being performed. Possible values:
- "categories": A set of user information categories is requested.
- "delete": The user account is being deleted. The module should remove its custom additions to the user object from the database.
- "form": The user account edit form is about to be displayed. The module should present the form elements it wishes to inject into the form.
- "insert": The user account is being added. The module should save its custom additions to the user object into the database and set the saved fields to NULL in $edit.
- "login": The user just logged in.
- "logout": The user just logged out.
- "load": The user account is being loaded. The module may respond to this and insert additional information into the user object.
- "update": The user account is being changed. The module should save its custom additions to the user object into the database and set the saved fields to NULL in $edit.
- "validate": The user account is about to be modified. The module should validate its custom additions to the user object, registering errors as necessary.
- "view": The user's account information is being displayed. The module should format its custom additions for display.
&$edit: The array of form values submitted by the user.
&$user: The user object on which the operation is being performed.
$category: The active category of user information being edited.
Return value
This varies depending on the operation.
- "categories": A linear array of associative arrays. These arrays have keys:
- "name": The internal name of the category.
- "title": The human-readable, localized name of the category.
- "weight": An integer specifying the category's sort ordering.
- "insert": None.
- "update": None.
- "delete": None.
- "login": None.
- "logout": None.
- "load": None.
- "form": A linear array of form groups for the specified category. Each group
is represented as an associative array with keys:
- "title": The human-readable, localized name of the group.
- "data": A string containing the form elements to display.
- "weight": An integer specifying the group's sort ordering.
- "validate": None.
- "view": An associative array of strings to display, keyed by category name.
Related topics
13 functions implement hook_user()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- block_user in modules/
block.module - Implementation of hook_user().
- blogapi_validate_user in modules/
blogapi.module - Ensure that the given user has permission to edit a blog.
- 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.
- blog_user in modules/
blog.module - Implementation of hook_user().
1 invocation of hook_user()
- user_logout in modules/
user.module - Menu callback; logs the current user out, and redirects to the home page.
File
- developer/
hooks/ core.php, line 1077 - These are the hooks that are invoked by the Drupal core.
Code
function hook_user($op, &$edit, &$user, $category = NULL) {
switch ($op) {
case 'view':
if ($user->signature) {
return array(
'account' => form_item(t('Signature'), check_output($user->signature)),
);
}
break;
case 'form':
// When user tries to edit his own data:
if ($category == 'account') {
return array(
array(
'title' => t('Personal information'),
'data' => form_textarea(t('Signature'), 'signature', $user->signature, 70, 3, t('Your signature will be publicly displayed at the end of your comments.') . '<br />' . filter_tips_short()),
'weight' => 0,
),
);
}
}
}