From The Blog

Drupal: doing an action in more safe way as another user.

30 January 2012, in Drupal

To do an action as another user "Administrator for example" for any reason "maybe to run it in a cron job" in a safe way:

global $user;
$currentuser = $user;
session_
save_session(FALSE);
$user = user_
load(array('uid' => 1));

//action_as_another_user_here();

$user = $currentuser;
session_save_session(TRUE);



Post a Comment