Editing comment without "administer comments" perm causes created date to be overridden

Created on 22 November 2018, over 6 years ago
Updated 24 April 2025, 12 days ago

If a user does not have the "administer comments" permission and attempts to edit a comment, the comment "created" date will be overridden with the current date/time.

The reason this happens is due to the following code in core's comment_form function:

  // Prepare default values for form elements.
  if ($is_admin) {
    $author = (!$comment->uid && $comment->name ? $comment->name : $comment->registered_name);
    $status = (isset($comment->status) ? $comment->status : COMMENT_NOT_PUBLISHED);
    $date = (!empty($comment->date) ? $comment->date : format_date($comment->created, 'custom', 'Y-m-d H:i O'));
  }
  else {
    if ($user->uid) {
      $author = $user->name;
    }
    else {
      $author = ($comment->name ? $comment->name : '');
    }
    $status = (user_access('skip comment approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED);
    $date = '';
  }

A default value for $date is only set if the user is an admin, otherwise it is left blank. A blank value in comment_save is interpreted to mean that a value needs to be set to the current timestamp, overriding whatever existed the database.

The attached patch intercepts comment_form when editing a comment and the user does not have "administer comments". It then adds a #default_value for author date based on the current created time of the comment.

See attached, thanks.

πŸ› Bug report
Status

Closed: outdated

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ron_s

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024