Is it possible to generate the content of the view as a specific user. So only the content the user has access to is rendered.

//Get view
$view = views_get_view("list_nodes");
//Pass arguments
$view->args = $locatie;
//Generate content
$content = $view->execute_display("block");

I got a custom module wich gets a list of users, to all those users the content of this view need to be send. But only the content the use has access to.


To render a view programmatically as a specific user, you need to adjust the global $user variable.

//Run script as a sepcific user
global $user;
$original_user = $user;
$user = user_load($uid);

//Your code goes here

//Return global variable to its orignal value
$user = $original_user;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.