Node adding by “node save”


Name variable (user name) should be always present when automatic node adding by node_save in Drupal. If this parameter is absent and adding goes by the role of superuser (uid=1) variable uid is ignored and changed to 0

(anonymous) -

$newnode = new stdClass();
$newnode->title = 'Welcome';
$newnode->body = "This is the welcome page for your site. Replace this text with whichever content you'd like to use for your welcome page.";
global $user;
$newnode->uid = $user->uid;
$newnode->name = $user->name;
$newnode->type = 'page';
$newnode->status = 1;
$newnode->promote = 0;
node_save($newnode);