Q:

Modify value only if node is new

I am using the following function to alter the node's data before saving it to the database.
function mymodule_node_presave($node) {
  if ($node->type="mytype") {
    if ($node->is_new) {
      $node->status = 0;
    }
  }
}

How do I know that the node is new and not updated/edited? In the example, you may see I have used $node->is_new, and I need to make sure that is correct. So is it?

A:

The is_new property is set by the node_save function, which is the same function that will invoke hook_node_presave - so your are safe in your assumption that this property will be present.
If you were not doing this in hook_node_presave, another way of testing if a node is new is by checking if the nid property is present and non-zero:
if (empty($node->nid)) {
  // ... this is a new node ...
}

