Skip to content

Comments: Prevent approved comments from being moved under pending parents#12639

Closed
tyxla wants to merge 1 commit into
WordPress:trunkfrom
tyxla:update/comment-parent-edit-pending-approved
Closed

Comments: Prevent approved comments from being moved under pending parents#12639
tyxla wants to merge 1 commit into
WordPress:trunkfrom
tyxla:update/comment-parent-edit-pending-approved

Conversation

@tyxla

@tyxla tyxla commented Jul 22, 2026

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/65688

This PR prevents an approved comment from being moved below a pending comment.

When threaded comments are enabled, the public comment query starts with approved top-level comments and then loads their replies. If an approved comment has a pending parent, the parent is not loaded. As a result, the approved child is also missing from the public comment list.

This is a follow-up to #12406 (original ticket 65570).

Changes

  • Only approved parents are shown when editing an approved comment.
  • Pending comments can still use approved or pending parents.
  • Server-side validation rejects a pending parent when the final status of the child is approved.
  • The validation uses the status submitted in the same update.
  • PHPUnit tests cover the parent selector, server validation, and status changes made during the update.

Testing

  • Enable threaded comments.
  • Create an approved comment and a pending comment on the same post.
  • Edit the approved comment.
  • Confirm that the pending comment is not available as a new parent.
  • Edit a pending comment.
  • Confirm that the pending comment is available as a parent.
  • Try to submit an approved comment with a pending parent.
  • Confirm that the update is rejected.
  • The following PHPUnit tests pass:
npm run test:php -- tests/phpunit/tests/admin/EditFormComment_Test.php
npm run test:php -- tests/phpunit/tests/admin/includes/comment/EditComment_Test.php

Use of AI Tools

AI assistance: Yes
Tool(s): Codex
Model(s): 5.6 Sol
Used for: Research and coding; final implementation and tests were reviewed and edited by me.

@tyxla tyxla self-assigned this Jul 22, 2026
Copilot AI review requested due to automatic review settings July 22, 2026 11:37
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props tyxla.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a threaded-comments integrity issue where an approved comment can end up under an unapproved (pending) parent, which can cause the approved child to disappear from the public threaded comment query. It tightens the Edit Comment UI parent picker and adds server-side validation plus PHPUnit coverage to prevent creating that state.

Changes:

  • Restricts the Edit Comment parent dropdown so approved comments only list approved parents, while pending comments may list pending parents.
  • Adds server-side validation in edit_comment() to reject pending parents when the resulting child status is approved.
  • Extends PHPUnit tests for the parent selector and edit_comment() validation.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/wp-admin/edit-form-comment.php Filters which parent statuses appear in the “In reply to” dropdown based on the edited comment’s approval state.
src/wp-admin/includes/comment.php Adds parent-status validation when editing a comment’s parent, intended to prevent approved children under non-approved parents.
tests/phpunit/tests/admin/EditFormComment_Test.php Adds coverage for excluding pending parents for approved comments and including them for pending comments.
tests/phpunit/tests/admin/includes/comment/EditComment_Test.php Adds tests for rejecting pending parents when the child is (or becomes) approved, and updates the helper to submit status.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wp-admin/includes/comment.php
Comment thread tests/phpunit/tests/admin/includes/comment/EditComment_Test.php
pento pushed a commit that referenced this pull request Jul 22, 2026
…rents.

An approved comment must have an approved parent, otherwise it drops out of
the public comment list when its pending parent is not loaded.

`edit_comment()` now rejects a pending parent whenever the child's final
status is approved, using the `comment_approved` value submitted in the same
update. The edit screen offers only approved parents when editing an approved
comment, while pending comments may still use either. PHPUnit tests cover the
parent selector, the server-side validation, and status changes made during
the update.

Developed in: #12639

Follow-up to [62673].

Props tyxla, youknowriad.
Fixes #65688.

git-svn-id: https://develop.svn.wordpress.org/trunk@62826 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62826
GitHub commit: 1325dea

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Jul 22, 2026
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Jul 22, 2026
…rents.

An approved comment must have an approved parent, otherwise it drops out of
the public comment list when its pending parent is not loaded.

`edit_comment()` now rejects a pending parent whenever the child's final
status is approved, using the `comment_approved` value submitted in the same
update. The edit screen offers only approved parents when editing an approved
comment, while pending comments may still use either. PHPUnit tests cover the
parent selector, the server-side validation, and status changes made during
the update.

Developed in: WordPress/wordpress-develop#12639

Follow-up to [62673].

Props tyxla, youknowriad.
Fixes #65688.
Built from https://develop.svn.wordpress.org/trunk@62826


git-svn-id: http://core.svn.wordpress.org/trunk@62106 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants