[support] How to bypass permissions for node_save() ?

Ted ted-drupalists at webfirst.com
Wed Mar 23 19:28:11 UTC 2011


On 3/23/2011 12:18 PM, Xavier Bestel wrote:
>>> How can I bypass the permissions system to make node_save() work ?
>>> I'm using Drupal 6.
>> user_access caches perms, otherwise you would be able to temporarily add
>> a role with 'administer nodes'. Instead, you'll need to swap out the
>> global $user for uid 1 temporarily (and rename your local $user var).
>> After you're done with the node_save, remember to swap the old $user back.
> Great !
>
> Would something like that work (I'm not a true drupalist;) ?
>
> global $user;
> $usersave = $user;
> $user = user_load(1);
>
> ... do stuff with node_save() ...
>
> $user = $usersave;
At first glance that looks okay. Give it a shot!


More information about the support mailing list