WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#35464 closed defect (bug) (fixed)

Documentation of WP_Comment incorrectly describes $comment_author as an ID

Reported by: meitar Owned by: rachelbaker
Milestone: 4.5 Priority: normal
Severity: normal Version: 4.4
Component: Comments Keywords: has-patch 2nd-opinion
Focuses: docs Cc:

Description

Super minor, but the docblock for WP_Comment::$comment_author says it's where the "comment author ID" is stored, but it actually stores the comment author's username. The comment author's ID is actually stored in WP_Comment::$user_id, whose docblock is correct.

A trivial patch is attached to this ticket to show what I mean.

Attachments (3)

35464.diff (329 bytes) - added by meitar 4 years ago.
Fix documentation error in WP_Comment class.
35464.2.diff (336 bytes) - added by meitar 4 years ago.
Fix docblock of WP_Comment::$comment_author to remark that it contains the commenter's display name, not their user ID.
35464.3.diff (667 bytes) - added by meitar 4 years ago.
Docblock with detailed description of what WP_Comment::$comment_author contains for commenters if they are logged in and if they are not.

Download all attachments as: .zip

Change History (12)

@meitar
4 years ago

Fix documentation error in WP_Comment class.

#1 follow-up: @knutsp
4 years ago

It's not login. It's the commenter's name. For a logged in commenter it's the display name, AFAIK.

#2 in reply to: ↑ 1 @meitar
4 years ago

Replying to knutsp:

It's not login. It's the commenter's name. For a logged in commenter it's the display name, AFAIK.

I don't think that's correct. A simple var_dump($comment->comment_author) (where $comment is a WP_Comment object) returns the user's login name, not the user's display name, even when one is set.

#3 follow-up: @knutsp
4 years ago

Inspecting the database table wp_comments on my site, where I recently left a comment as a logged in user, I see my display name in the comment_author column. This display name is different from my login. This name is shown on the front as the name or identity of the commenter.

For not logged in users the property, and the column, contains the name given by the (anonymous) commenter through the comment form field. Such commenter may not have a login at all (not registered).

Did you also dump the user_id to verify that the comment is from a logged in user?

@meitar
4 years ago

Fix docblock of WP_Comment::$comment_author to remark that it contains the commenter's display name, not their user ID.

#4 in reply to: ↑ 3 @meitar
4 years ago

  • Keywords has-patch added

Replying to knutsp:

Inspecting the database table wp_comments on my site, where I recently left a comment as a logged in user, I see my display name in the comment_author column. This display name is different from my login. This name is shown on the front as the name or identity of the commenter.

My apologies! You are correct, and I was wrong. I attached a second, corrected diff to this effect.

#5 @rachelbaker
4 years ago

@meitar Hey, thanks for the ticket and the patch. Commenter's that are not logged-in typically have enter their name into an input field that just asks for their name. If a commenter is already logged-in this field doesn't appear. Which means: the comment_author can *either* be the commenter's name or the display name for logged-in users.
Would you mind refreshing the patch?

Last edited 4 years ago by rachelbaker (previous) (diff)

#6 @rachelbaker
4 years ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to 4.5

@meitar
4 years ago

Docblock with detailed description of what WP_Comment::$comment_author contains for commenters if they are logged in and if they are not.

#7 @meitar
4 years ago

  • Keywords 2nd-opinion added; needs-refresh removed

@rachelbaker Thanks for that more nuanced explanation. The refreshed patch is my attempt at explaining this detail to myself when I inevitably forget it in the future. Let me know if the description in the third patch proposal (attachment:35464.3.diff) is acceptable.

#8 @rachelbaker
4 years ago

  • Owner set to rachelbaker
  • Resolution set to fixed
  • Status changed from new to closed

In 36332:

Comments: Correct description of comment_author property in WP_Comment class.

The comment_author property is the comment author’s name, not an ID.

Props meitar.

Fixes #35464.

#9 @johnbillion
4 years ago

  • Version changed from trunk to 4.4
Note: See TracTickets for help on using tickets.