Programmatically delete a node and redirect user

Public

This is a simple function to delete a node by passing the node object or the nid. There is an option to redirect the user to a destination if you pass that variable in.

Get raw version
php
  1. function api_node_delete($node, $destination = NULL) {
  2. // Pass in either the node object of a node id
  3. if(is_object($node)) {
  4. $nid = $node->nid;
  5. } elseif(is_numeric($node)) {
  6. $nid = $node;
  7. }
  8. node_delete($nid);
  9.  
  10. // option to pass in a destination string
  11. // Example: node/1 or 'http://mysite.com/node/1
  12. if(!empty($destination)) {
  13. drupal_goto($destination);
  14. }
  15. }