WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#34954 closed defect (bug) (fixed)

Comments Created Without a `comment_post_ID` Are Not Editable

Reported by: rachelbaker Owned by: rachelbaker
Milestone: 4.5 Priority: normal
Severity: normal Version: 4.2
Component: Comments Keywords: good-first-bug has-patch has-unit-tests
Focuses: administration Cc:
PR Number:

Description

If a comment is created via wp_insert_comment() without the optional comment_post_ID parameter, the value in the database is 0. The comment will display in the Comments list table, but if you try to edit the comment your changes never save.

This is (at least in part) due to the following code from src/wp-includes/comment.php:

// Make sure that the comment post ID is valid (if specified).
	if ( isset( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) {
		return 0;
}

The check here should be changed to ! empty() since isset() would be true for a 0 value.

Attachments (2)

34954.patch (499 bytes) - added by subharanjan 4 years ago.
34954.1.patch (1.5 KB) - added by rachelbaker 4 years ago.
Added unit tests

Download all attachments as: .zip

Change History (9)

#1 @SergeyBiryukov
4 years ago

  • Version set to 4.2

Introduced in [31195].

#2 @rachelbaker
4 years ago

  • Milestone changed from Awaiting Review to 4.5

#3 @rachelbaker
4 years ago

  • Keywords good-first-bug added

@subharanjan
4 years ago

#4 @boonebgorges
4 years ago

  • Keywords has-patch needs-unit-tests added; needs-patch removed

Patch looks good. Would be nice to have a unit test describing the bug so we don't do this again.

@rachelbaker
4 years ago

Added unit tests

#5 @rachelbaker
4 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

@boonebgorges Added unit tests in 34954.1.patch, can you review the tests for me?

#6 @boonebgorges
4 years ago

Thanks @rachelbaker - Test looks good, though I'd change assertEquals to assertSame. Side note: pretty cool how wp_update_comment() returns an integer.

#7 @rachelbaker
4 years ago

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

In 35853:

Comments: Comments don’t need no Post ID when created, so they don’t be needing one to be edited.

In wp_update_comment() only check if the given comment_post_ID is valid if it isn’t 0. This allows comments that were created programmatically via wp_insert_comment() without the (optional) comment_post_ID parameter to be edited.

Props subharanjan for the initial patch.
Fixes #34954

Note: See TracTickets for help on using tickets.