What block visibility PHP snippet would show a block only on node pages that the loged-in user can edit? The user may not own the node. In my case, I want to show the Content Complete block to people who can actually populate missing fields.
+3
A:
check for node_access("update", $node) (more on http://api.drupal.org/api/function/node_access/6)
//first check whether it is a node page
if(arg(0) == 'node' && is_numeric(arg(1))){
//load $node object
$node = node_load(arg(1))
//check for node update access
if (node_access("update", $node)){
return TRUE;
}
}
barraponto
2010-05-20 17:14:21
+1 - a straight solution. I'd replace the if clause with a `return node_access("update", $node)`, though ;)
Henrik Opel
2010-05-20 18:38:36
you're right, although my code is slightly more legible. but if the user knows php, yours is the best suggestion.
barraponto
2010-05-21 17:42:01
just do it.btw, remove those off topic comments and, if needed, create another question.
barraponto
2010-05-22 00:34:34
A:
Following is barraponto's solution rewritten for noobs like me and to support multiple conditions.
<?php
$match = FALSE;
// Show block only if user has edit privilges for the node page
// first check whether it is a node page
if(arg(0) == 'node' && is_numeric(arg(1))){
//load $node object
$node = node_load(arg(1));
//check for node update access
if (node_access("update", $node)){
$match = TRUE;
}
}
return $match;
?>
wgrunberg
2010-05-21 23:05:05