Take a look at:
which describes how to safely impersonate another user.
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Ted Sent: Wednesday, March 23, 2011 12:28 PM To: Xavier Bestel Cc: support@drupal.org Subject: Re: [support] How to bypass permissions for node_save() ?
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!