REST API: Fix the comment author object for comments whose author info has been edited. #7707
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
wp-admin
allows a user to edit a comment author's name, email, and URL. This can be done for both logged-out and logged-in users.If a comment author is logged-in when commenting, the stored comment will also have the comment author's user ID. The presence of this ID will fail this check in
get_author()
, and the author object returned by an API call will reflect the user based on that ID; any edited name, email, or URL in the comments table will be bypassed.This PR seems like the simplest way to get at the edited data: if the "author" passed in is a comment row (as determined by the presence of
comment_author_email
, which is required when commenting), return data from that comment. Note that this will mean losing the original commenter's user ID and associated avatar in the response, but I think this would be desirable. Otherwise, the comment author will be displayed with their edited email, for example, and an avatar associated to another (the original) email.Another approach would be to have the same data returned for all authors (get rid of the check referenced above), but override any possible edited commenter's data. However, this could change the nature of the response; it will add an (empty)
site_id
toauthor
, andID
would no longer be0
in the case of logged-in and edited comment authors. This would be a more consistent shape, but the effect would be more unpredictable – so I've proposed the former for now.D7075-code