function commentaccess_requires_approval in Comment Access 7
Returns TRUE if the specified comment requires approval by the comment's node's owner.
Parameters
object $comment: The comment.
Return value
bool TRUE if the comment require approval, FALSE if not. NULL if the node's owner has no administer/approval access. In this case, the general comment access rules are used.
1 call to commentaccess_requires_approval()
- commentaccess_comment_presave in ./
commentaccess.module - Implementation of hook_comment_presave()
File
- ./
commentaccess.module, line 444 - Provides users with permissions for comments on nodes they own.
Code
function commentaccess_requires_approval($comment) {
// Check if the comment is a node comment.
if (empty($comment->nid)) {
return NULL;
}
$node = node_load($comment->nid);
if (empty($node)) {
return NULL;
}
// Check for known owner.
$owner = user_load($node->uid);
if (empty($owner)) {
// Owner unknown: use general comment rules.
return NULL;
}
// Check if the owner has administer or approval access for this node type.
if (!user_access('administer comments on own ' . $node->type, $owner) && !user_access('approve comments on own ' . $node->type, $owner)) {
// No access: use general comment rules.
return NULL;
}
global $user;
if ($owner->uid == $user->uid) {
// Node owner is comment owner: no approval needed.
return FALSE;
}
elseif (user_access('skip comment approval')) {
// User bypasses approval.
return FALSE;
}
else {
// Check if the node author wants to skip approvals.
if (!empty($owner)) {
$skip_approval_field = "commentaccess_skip_" . $node->type;
$commentaccess_settings = _commentaccess_get_account_settings($owner);
return empty($commentaccess_settings[$skip_approval_field]);
}
else {
return FALSE;
}
}
}