Automatically create a Drupal node when a user registers
Sometimes projects come up that have requirements that cannot be solved with an out-of-the-box Drupal install. A project I worked on some time ago required that I store a node every time a user registered for an account. The details of the project are a little fuzzy for me now, so I’ll just skip right to the example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function mymodule_user($op, &$edit, &$account, $category = NULL){ switch($op){ case 'insert': // Automatically create the note settings (content profile) node for this new user $newnode = new stdClass(); $newnode->title = "Note settings user {$account->uid}"; $newnode->uid = $account->uid; $newnode->type = 'note_settings'; $newnode->status = 1; $newnode = node_submit($newnode); node_save($newnode); break; //insert } } |
This example shows how simple it is to programmatically create a node, and also shows the proper way to hook into the user system.