WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#30946 closed defect (bug) (fixed)

wp_update_comment() can't update the comment_post_ID

Reported by: tyxla Owned by: pento
Milestone: 4.2 Priority: normal
Severity: normal Version: 4.1
Component: Comments Keywords: has-patch
Focuses: Cc:
PR Number:

Description

The current implementation of wp_update_comment() does not allow to change the comment_post_ID - the ID of the post that the comment is posted to. Even if comment_post_ID is passed to the array parameter, it is being stripped off the database update query.

So, the following code:

wp_update_comment(array(
	'comment_ID' => 1,
	'comment_post_ID' => 2,
	'comment_content' => 'test text here',
));

will not change the comment_post_ID to 2, even if 2 is a valid post ID.

Attachments (2)

wp_update_comment.patch (2.4 KB) - added by tyxla 5 years ago.
Allowing the comment_post_ID to be updated, and if passed, make sure that it corresponds to a valid post ID. Adding a unit test assertion in Tests_Comment::test_wp_update_comment() for that functionality.
30946.diff (2.4 KB) - added by rachelbaker 5 years ago.
Minor code formatting change from wp_update_comment.patch

Download all attachments as: .zip

Change History (10)

#1 @tyxla
5 years ago

  • Keywords needs-patch needs-unit-tests needs-testing added

#2 @SergeyBiryukov
5 years ago

  • Keywords needs-testing removed

Related: #30307, #30627.

#3 @SergeyBiryukov
5 years ago

  • Milestone changed from Awaiting Review to 4.2

@tyxla
5 years ago

Allowing the comment_post_ID to be updated, and if passed, make sure that it corresponds to a valid post ID. Adding a unit test assertion in Tests_Comment::test_wp_update_comment() for that functionality.

#4 @tyxla
5 years ago

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

@rachelbaker
5 years ago

Minor code formatting change from wp_update_comment.patch

#5 @rachelbaker
5 years ago

Confirmed bug and tested submitted patch. Patch looks good. Added minor formatting adjustment.

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

This ticket was mentioned in Slack in #core by rachelbaker. View the logs.


5 years ago

#8 @pento
5 years ago

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

In 31195:

Allow comment_post_ID to be passed to wp_update_comment(), so that a comment can be moved to a different post.

Props tyxla, rachelbaker

Fixes #30946

Note: See TracTickets for help on using tickets.