Skip to content

Comments: Restore child notes trashed along with their parent note - #14044

Closed
t-hamano wants to merge 5 commits into
WordPress:trunkfrom
t-hamano:66255-restore-child-notes-on-untrash
Closed

t-hamano wants to merge 5 commits into
WordPress:trunkfrom
t-hamano:66255-restore-child-notes-on-untrash

Conversation

@t-hamano

@t-hamano t-hamano commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Backport of WordPress/gutenberg#84100

wp_trash_comment() also trashes the child notes of a top-level note, but wp_untrash_comment() has no counterpart, so the child notes stay in the Trash when the parent note is restored.

Following wp_trash_post_comments() / wp_untrash_post_comments():

  • When a top-level note is trashed, the child notes not yet in the Trash are trashed along with it, and their IDs are recorded in the parent's _wp_trash_meta_children meta.
  • When the parent note is untrashed, only the recorded child notes still in the Trash are restored, and the meta is deleted.

A child note the user trashed individually before trashing the parent is not recorded, so it stays in the Trash.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Implementation and tests; reviewed and verified by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with Claude Code

`wp_trash_comment()` also trashes the child notes of a top-level note, but `wp_untrash_comment()` had no counterpart, so the child notes stayed in the Trash when the parent note was restored.

The child notes trashed along with a top-level note are now recorded in the parent's `_wp_trash_meta_children` meta, and only those still in the Trash are restored with it. A child note trashed individually beforehand stays in the Trash.

See #66255.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
// Record the children trashed along with the parent, so that they can be restored with it.
delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_children' );
if ( $children ) {
add_comment_meta( $comment->comment_ID, '_wp_trash_meta_children', $children );

@t-hamano t-hamano Oct 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The key follows the existing _wp_trash_meta_* convention for trash-related meta:

  • _wp_trash_meta_status / _wp_trash_meta_time: Stored on each trashed post or comment itself.
  • _wp_trash_meta_comments_status: Stored on a trashed post by wp_trash_post_comments() to record the comments trashed along with it, and deleted by wp_untrash_post_comments() once they are restored.

Unlike _wp_trash_meta_comments_status, it only stores the IDs, since each child note's original status is already stored in its own _wp_trash_meta_status by wp_trash_comment().

@github-actions

github-actions Bot commented Oct 6, 2026

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.

@t-hamano
t-hamano marked this pull request as ready for review October 6, 2026 10:17
@github-actions

github-actions Bot commented Oct 6, 2026 •

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.

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

Props wildworks, mukesh27, peterwilsoncc.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Comment thread tests/phpunit/tests/comment.php
…sh tests.

Co-Authored-By: Claude <noreply@anthropic.com>

@peterwilsoncc peterwilsoncc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some additional unit tests to ensure the following would be dandy:

  • the trashing of parent comments of other types- comments, pings, etc- does not modify the children
  • other comment types don't get the meta data
  • other comment types don't modify children on untrashing

@t-hamano

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback! I've added some tests. As a result, the PR now includes the following new tests:

  • test_wp_trash_comment_does_not_trash_children_of_other_comment_types: Tests that trashing a top-level comment of a type other than note does not trash its children.
  • test_wp_trash_comment_does_not_record_children_of_other_comment_types: Tests that trashing a top-level comment of a type other than note does not record its children in the _wp_trash_meta_children meta.
  • test_wp_untrash_comment_does_not_modify_children_of_other_comment_types: Tests that untrashing a top-level comment of a type other than note does not modify its children, whether they are in the Trash or held.

@peterwilsoncc peterwilsoncc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @t-hamano, these additional tests look good to me.

Approving for you to commit after the merge conflicts are resolved.

# Conflicts:
#	src/wp-includes/comment.php
#	tests/phpunit/tests/comment.php
wporg-sync pushed a commit that referenced this pull request Oct 23, 2026
Restoring a top-level note from the Trash now also restores the child notes that were trashed along with it. Child notes the user trashed individually before trashing the parent stay in the Trash.

Developed in: #14044

Props wildworks, mukesh27, peterwilsoncc.
Fixes #66255.

git-svn-id: https://develop.svn.wordpress.org/trunk@64684 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: 64684
GitHub commit: 3fb786c

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 Oct 23, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 23, 2026
Restoring a top-level note from the Trash now also restores the child notes that were trashed along with it. Child notes the user trashed individually before trashing the parent stay in the Trash.

Developed in: WordPress/wordpress-develop#14044

Props wildworks, mukesh27, peterwilsoncc.
Fixes #66255.
Built from https://develop.svn.wordpress.org/trunk@64684


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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants