function comment_perm_post_without_permission_access in Comment Permissions 6
Same name and namespace in other branches
- 7 comment_perm.module \comment_perm_post_without_permission_access()
Can the current user post comments without permission?
1 call to comment_perm_post_without_permission_access()
- comment_perm_comment in ./
comment_perm.module - Implementation of hook_comment().
File
- ./
comment_perm.module, line 190 - Module to control commenting permissions by role and by node type.
Code
function comment_perm_post_without_permission_access($node) {
global $user;
if (is_numeric($node)) {
$node = node_load($node);
}
// get node types managed by comment_perm
$types = variable_get('comment_perm_node_types', array());
if ($types[$node->type]) {
// allow comment administrators to edit any comment
if (user_access('administer comments')) {
return TRUE;
}
// get assigned permissions for this user's role
$access_all = user_access($node->type . ': comment without approval on any ' . $node->type . ' content');
$access_own = user_access($node->type . ': comment without approval on own ' . $node->type . ' content');
// does the user have permission to post comments without permission on nodes of this type?
if ($access_all) {
return TRUE;
}
// does the user have permission to post comments on their own nodes?
if ($access_own && $user->uid == $node->uid) {
return TRUE;
}
// get assigned permissions for this user's role
if (user_access($node->type . ': edit own comments on ' . $node->type . ' content')) {
return TRUE;
}
// comment_perm controlled node types default to FALSE
return FALSE;
}
// non-comment_perm controlled node types default to whatever permission Drupal gives them.
return user_access('post comments without approval') ? TRUE : FALSE;
}