Skip to content

Instantly share code, notes, and snippets.

@greggles
Created September 26, 2011 21:59
Show Gist options
  • Save greggles/1243531 to your computer and use it in GitHub Desktop.
Save greggles/1243531 to your computer and use it in GitHub Desktop.
1290624_example3
<?php
/**
* Provides an API function to load/tweak a user's name.
* Called by a module which has already checked permission and the validity of the $uid.
*/
function example_module_usertweak($uid) {
global $user;
drupal_set_message(t('Thanks, @user, for tweaking this!', array('@user' => $user->name));
// Save the original user.
$original_user = $user;
// Now load the current user and call a hook to allow modules to tweak it.
$user = user_load($uid);
$user = module_invoke_all('example_module_usertweak', $user);
user_save($user);
// Now switch back to the original user.
$user = $original_user;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment