Skip to content

Instantly share code, notes, and snippets.

@zerolab
Created February 7, 2011 17:00
Show Gist options
  • Save zerolab/814716 to your computer and use it in GitHub Desktop.
Save zerolab/814716 to your computer and use it in GitHub Desktop.
Drupal: perform any action when a node is published
<?php
/**
* Implementation of hook_nodeapi()
* Perform any action when a node is published
* Note: because no extra data added via $op = 'load', a node "reload" is necessary on presave
*/
function mymodule_nodeapi(&$node, $op) {
if ($op == 'presave') {
if ($node->type == 'my_node_type' && $node->status == 1) {
// Get node state as of node_load()
$n = node_load($node->nid);
if ($n->status == 0) {
//the node has just been published. do something
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment