Search code examples
phpdrupaldrupal-7

How to delete user and node, drupal 7?


I have created a module which adds a new node(with user info) if a user is added. Now I want to implement a user_delete hook that deletes the node if the user is deleted. I don't know how to implement this.

This code adds a new node for new user:

function user_profile_user_insert(&$edit, $account, $category) {

    $node = new stdClass();
    $node->type = 'members';
    node_object_prepare($node);

    //dvm($account);
    $node->title = $account->name;

    $user_info = user_load($account->uid);

    $node->field_user["und"][0]["uid"] = $account->uid;


    $path = $account->name;

    $node->path = array('alias' => $path);

    node_save($node);
}

Solution

  • try this

    function node_delete($nid) {
     node_delete_multiple(array($nid));
    }