At the bottom of a View i want to print a small message for users that have the permission to edit the node. Now i can find the code if a user is logged in or not and how to print his / her role. But how can i determine with PHP if the user has the rights to EDIT the actual node?

Comments

vertazzar’s picture

<?php 
global $user;
// we check if the user has a role, example "authenticated user"
if (in_array('role that has permission to edit nodes', array_values($user->roles))) {
// we print -- user->name, you have permission to edit nodes!
 print $user->name;
print ', you have the permission to edit nodes!';

} 
else {
// in else you can print whatever you want. 
     print 'You dont have permission to edit nodes';
}
?>

you can put this code into block with php input format enabled.

MatthijsG’s picture

Tnx, but i need to enter the role-name. I work with OG, and a node is editable or not depending on membership, not on role.

======
There are 10 people who can count binary
They who can and they who don't

pbarnett’s picture

$node is the fully-loaded node object - you'll need to use node_load() if you just have the node ID

if (og_is_group_admin($node)) { // User can edit the node
  // your code
}

Pete.