You are here

function comment_delete_check_access in Comment Delete 7

Checks user access to delete specified comment.

Parameters

int $cid: Unique comment identification number.

Return value

bool Returns TRUE if user has access and FALSE otherwise.

1 call to comment_delete_check_access()
comment_delete_comment_view in ./comment_delete.module
Implements hook_comment_view().
1 string reference to 'comment_delete_check_access'
comment_delete_menu_alter in ./comment_delete.module
Implements hook_menu_alter().

File

./comment_delete.module, line 89
comment_delete.module

Code

function comment_delete_check_access($cid) {
  if (empty($cid) || !is_numeric($cid)) {
    return FALSE;
  }
  global $user;

  // Retrieve specified comment object.
  $comment = comment_load($cid);
  if (!isset($comment->cid)) {
    return FALSE;
  }
  $threshold = 0;

  // Calculate allowable comment deletion threshold.
  if ($threshold_setting = variable_get('comment_delete_threshold', 0)) {
    $threshold = time() - $comment->created > $threshold_setting;
  }

  // Check permissions for users own comment.
  if (user_access('delete any comment') && !$threshold || user_access('delete any comment anytime')) {
    return TRUE;
  }

  // Check permissions for any comment.
  if ((user_access('delete own comment') && !$threshold || user_access('delete own comment anytime')) && $user->uid == $comment->uid) {
    return TRUE;
  }
  return FALSE;
}