Created
October 24, 2015 13:25
-
-
Save anonymous/a8f0ddaff7a3b0bc1706 to your computer and use it in GitHub Desktop.
Safely run a function in Drupal as another user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function drupal_run_as($user, $func, $arg1) { | |
global $user; | |
$original_user = $user; | |
$old_state = drupal_save_session(); | |
drupal_save_session(FALSE); | |
$args = func_get_args(); | |
$user = array_shift($args); | |
$func = array_shift($args); | |
$r = call_user_func_array($func, $args); | |
$user = $original_user; | |
drupal_save_session($old_state); | |
return $r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment