How to force node.status=0 I need to force the status value of a node=0 when the user has a certain role.

I've made 

 function mymodule_node_save($node){
    if($node-&gt;type=="mytype") {
        global $user;
        if(in_array("simple",$user-&gt;roles)) {
            $node-&gt;status=0;
        }

    }
}


But the status is always saved as 1. What am i doing wrong?
@redhatlab is correct about Drupal 7 not invoking hook_node_save(). If you need to be sure the status is effectively set to 0, without other modules to alter it, I would use code similar to the following one.

function mymodule_node_insert($node) {
  mymodule_update_status($node);
}

function mymodule_node_update($node) {
  mymodule_update_status($node);
}

function mymodule_module_implements_alter(&amp;$implementations, $hook) {
  if ($hook == 'node_insert' || $hook == 'node_update') {
    $group = $implementations['mymodule'];
    unset($implementations['mymodule']);
    $implementations['mymodule'] = $group;
  }
}

function mymodule_update_status($node){
  if ($node-&gt;type == 'mytype' &amp;&amp; in_array('simple', $GLOBALS['user']-&gt;roles)) {
    $node-&gt;status = 0;
  }
}


The code checks the roles assigned to the currently logged-in user. If you want to check the roles assigned to the node author, you should use $node-&gt;uid to load the user object of the node author. It is then generally preferable to check the user has a specific permission, rather then checking which roles are assigned to the user.

node_save() first invokes hook_node_presave(), and then hook_node_insert(), or hook_node_update(). The code I wrote would allow your module to be the last one changing the node status.

References


node_save()
hook_module_implements_alter()