1 comment.module comment_access($op, Comment $comment = NULL)

Determines whether the current user has access to a particular comment.

Authenticated users can edit their comments, as long they have not been replied to. This prevents people from changing or revising their statements, based on the replies to their posts.

@since 1.13.0 The "create" $op option was added. @since 1.13.0 The "edit" $op option is deprecated. Use "update" instead.

Parameters

string $op: The operation to be performed on the comment. Possible values are:

  • create
  • view
  • update
  • delete
  • approve

Comment $comment: (optional) The comment object, or NULL when using 'create' op.

Return value

bool: TRUE if the current user has access to the comment, FALSE otherwise.

File

core/modules/comment/comment.module, line 1513
Enables users to comment on published content.

Code

function comment_access($op, Comment $comment = NULL) {
  if ($op == 'edit') {
    // Normalize 'edit' operation to 'update'.
    $op = 'update';
    // Log to watchdog for DX. @todo add watchdog_deprecated_parameter().
    $message = 'The function comment_access() was called with the operation <em>edit</em>. This operation is now named <em>update</em>. The <em>edit</em> operation will be removed in the next major release of Backdrop.';
    $variables = array();
    watchdog('comment', $message, $variables, WATCHDOG_DEPRECATED);
  }

  if ($op == 'create') {
    return Comment::createAccess();
  }
  else {
    return $comment->access($op);
  }
}