Actually...
Very often you want to put in a user name and user uid different from the admin who is running a script.
In my case, I am admin / uid 2, but I want the "webmaster" (uid 4) to figure as the author, so it would not be the current user.
It would be a parameter of some kind (in the running of the script, say).
Victor
Quoting Omar Abdel-Wahab <owahab@gmail.com>:
Assuming you might want to allow for possible other users than uid 1:
global $user;
> Any ideas why does this fails to set the node author:
$user = user_load(array('uid'=>$uid); //$uid is an optional function
parameter with a default of 1.
//If the action is a temporary switch to admin user be sure to save the
original //value of $user so you can reset it before exiting.
> $node = new stdClass();//change to
> $node->title = 'foo';
> $node->uid = 1;
$node->uid = $uid;
$node->name = $user->name;
> node_submit($node);
//Node submit is usually called after user clicks submit and is called to
//prepare the node for the save. Things like converting the $node from an
//array to an object, adding uid to the node, adding the teaser to the
node and
//invoking modules with _submit and _nodeapi hooks implemented. If you don't
//need or want these things then don't call it.
> node_save($node);//Node submit sets $node->uid to zero if $node->name isn't loaded by
>
> While this succeeds:
> $node = new stdClass();
> $node->title = 'foo';
> node_submit($node);
> $node->uid = 1;
> node_save($node);
>
user_load.