Make WordPress Core

Opened 6 weeks ago

Closed 4 weeks ago

#66255 closed defect (bug) (fixed)

Notes: Restore child notes trashed along with their parent note

Reported by: wildworks Owned by: wildworks
Priority: normal Milestone: 7.2
Component: Notes Version:
Severity: normal Keywords: has-patch has-unit-tests gutenberg-merge
Cc: Focuses:

Description

Gutenberg PR: ​https://github.com/WordPress/gutenberg/pull/84100

When a top-level note is trashed, wp_trash_comment() also trashes its child notes. However, wp_untrash_comment() has no counterpart for this: when the parent note is restored, its child notes stay in the trash.

To fix this, wp_untrash_comment() needs a counterpart to the child-trashing logic in wp_trash_comment(). The approach can follow the precedent of ​wp_trash_post_comments() / ​wp_untrash_post_comments():

  • When a top-level note is trashed, store the IDs of the child notes that are not yet in the trash (i.e. the ones being trashed along with the parent) in the parent note's _wp_trash_meta_children meta.
  • When the parent note is untrashed, restore only the recorded child notes that are still in the trash, then delete the meta.

Importantly, a child note the user trashed individually before trashing the parent should not be restored when the parent is trashed and then restored. The parent's trash/untrash cycle should only undo what it did itself.

Change History (4)

This ticket was mentioned in ​PR #14044 on ​WordPress/wordpress-develop by ​@wildworks.


6 weeks ago
#1

  • Keywords has-patch has-unit-tests added

Backport of ​https://github.com/WordPress/gutenberg/pull/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.

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

​@wildworks commented on ​PR #14044:


5 weeks ago
#2

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.

#3 @wildworks
4 weeks ago

  • Keywords gutenberg-merge added

#4 @wildworks
4 weeks ago

  • Owner set to wildworks
  • Resolution → fixed
  • Status new → closed

In 64684:

Comments: Restore child notes trashed with their parent note.

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: ​https://github.com/WordPress/wordpress-develop/pull/14044

Props wildworks, mukesh27, peterwilsoncc.
Fixes #66255.

Note: See TracTickets for help on using tickets.