WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#30944 closed defect (bug) (duplicate)

wp_insert_comment() allows to insert a comment with wrong or missing post ID

Reported by: tyxla Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: Comments Keywords:
Focuses: Cc:
PR Number:

Description

Currently wp_insert_comment() allows the insertion of a comment with no post ID specified, or with an invalid post ID (one that does not correspond to a valid post).

So the following use case:

wp_insert_comment( array() );

creates a comment with post ID 0, and the following use case:

wp_insert_comment( array('comment_post_ID' => 999999) );

creates a comment with post ID of 999999 (considering that 999999 does not correspond to a valid post).

Both of the created comments are invalid, as they "hang" in the middle of nowhere, attached to non-existing posts, and displaying weird results and errors in the Comments administration screen.

In order to fix this, the function should check the $comment_post_ID, and if it is invalid, false should be returned.

Change History (1)

#1 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #23931.

Note: See TracTickets for help on using tickets.