Actually...<br><br>Very often you want to put in a user name and user uid different from the admin who is running a script.<br><br>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.<br>
<br>It would be a parameter of some kind (in the running of the script, say).<br><br>Victor<br><br><div class="gmail_quote">On Wed, Mar 12, 2008 at 9:55 AM, Earnie Boyd <<a href="mailto:earnie@users.sourceforge.net">earnie@users.sourceforge.net</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Quoting Omar Abdel-Wahab <<a href="mailto:owahab@gmail.com">owahab@gmail.com</a>>:<br>
<br>
Assuming you might want to allow for possible other users than uid 1:<br>
<div class="Ih2E3d"><br>
> Any ideas why does this fails to set the node author:<br>
</div>global $user;<br>
$user = user_load(array('uid'=>$uid); //$uid is an optional function<br>
parameter with a default of 1.<br>
//If the action is a temporary switch to admin user be sure to save the<br>
original //value of $user so you can reset it before exiting.<br>
<div class="Ih2E3d">> $node = new stdClass();<br>
> $node->title = 'foo';<br>
> $node->uid = 1;<br>
</div>//change to<br>
$node->uid = $uid;<br>
$node->name = $user->name;<br>
> node_submit($node);<br>
//Node submit is usually called after user clicks submit and is called to<br>
//prepare the node for the save. Things like converting the $node from an<br>
//array to an object, adding uid to the node, adding the teaser to the<br>
node and<br>
//invoking modules with _submit and _nodeapi hooks implemented. If you don't<br>
//need or want these things then don't call it.<br>
<div class="Ih2E3d">> node_save($node);<br>
><br>
> While this succeeds:<br>
> $node = new stdClass();<br>
> $node->title = 'foo';<br>
> node_submit($node);<br>
> $node->uid = 1;<br>
> node_save($node);<br>
><br>
</div>//Node submit sets $node->uid to zero if $node->name isn't loaded by<br>
user_load.<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
Earnie -- <a href="http://for-my-kids.com/" target="_blank">http://for-my-kids.com/</a><br>
-- <a href="http://give-me-an-offer.com/" target="_blank">http://give-me-an-offer.com/</a><br>
<br>
</div></div></blockquote></div><br>