You are here

function comment_delete_access_check in Comment Delete 6

Checks if a user has access to delete a specific comment.

1 call to comment_delete_access_check()
comment_delete_link in ./comment_delete.module
Implementation of hook_link().
1 string reference to 'comment_delete_access_check'
comment_delete_menu_alter in ./comment_delete.module
Implementation of hook_menu_alter().

File

./comment_delete.module, line 47

Code

function comment_delete_access_check($cid) {
  if (empty($cid)) {
    return FALSE;
  }
  global $user;
  $comment = _comment_load($cid);

  // Determine if the deletion clock should be used.
  $clock_expired = FALSE;
  if ($clock = variable_get('comment_delete_clock', 0)) {
    $clock_expired = time() - $comment->timestamp > $clock;
  }

  // Check if user has permission to delete any comment.
  if (user_access('delete any comment') && !$clock_expired || user_access('delete any comments at anytime')) {
    return TRUE;
  }

  // User must have delete own comments permission.
  if (user_access('delete own comments', $user) && !$clock_expired || user_access('delete own comments at anytime')) {
    if ($user->uid == $comment->uid) {
      return TRUE;
    }
  }
  return FALSE;
}