Skip to content

Conversation

@adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Nov 10, 2025

Fixes WordPress/gutenberg#72862

Needs tests.

Trac ticket:


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.

@github-actions
Copy link

github-actions bot commented Nov 10, 2025

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 adamsilverstein, desrosj, wildworks, mamaduka, karthickmurugan, jeffpaul, hanneslsm.

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

@github-actions
Copy link

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

Copy link
Member

@desrosj desrosj left a comment

Choose a reason for hiding this comment

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

This looks like it will work well for trashing Notes, but only when the trash feature is enabled (setting EMPTY_TRASH_DAYS to a falsey value will bypass the trash and immediately delete comments and posts).

In that case, wp_delete_comment() is called very early in the function.

Instead of introducing a second function for this scenario, maybe making wp_trash_comment_children() function more generic. wp_handle_comment_children(), or something similar. Then if ( ! EMPTY_TRASH_DAYS ) { can be included to perform the desired action.

*
* @param int $comment_id The comment ID.
*/
function wp_trash_comment_children( $comment_id ) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we use wp_trash_note_children() or wp_trash_note_replies() instead here?

Thinking that this would make it more obvious that it's currently only intended for Notes. Down the road if we want this to be more general, wp_trash_note_children() could become a pass through to wp_trash_comment_children( $type = 'note' ), or whatever that ends up being.

If not, then the docblock should probably just say "a comment's children".

wp_trash_comment_children( $comment->comment_ID );
}

return true;
Copy link
Member

Choose a reason for hiding this comment

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

What happens if some children are trashed but not all? I think that as is, the status would always be true. I think that's fine because the top-level comment was trashed, which is the ID passed to the function.

I don't think we need to address this now, but it will likely come up in the future.

* If Trash is disabled, comment is permanently deleted.
*
* @since 2.9.0
* @since 6.9.1 Any child notes are deleted when deleting a note.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @since 6.9.1 Any child notes are deleted when deleting a note.
* @since 6.9.0 Any child notes are deleted when deleting a note.

/**
* Delete all of a note's children (replies).
*
* @since 6.9.1
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @since 6.9.1
* @since 6.9.0

*
* @covers ::wp_trash_comment
*/
public function test_wp_trash_comment_does_not_trash_child_comments() {
Copy link
Member

Choose a reason for hiding this comment

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

Could we add an assertion to confirm that replies are deleted with the top level note when it has been resolved? Just to cover more combinations.

@t-hamano
Copy link
Contributor

I think there are two areas for improvement in the wp_trash_comment_children() function:

  • It doesn't delete nested comments. This isn't a problem at the moment, but the notes might support nested replies in the future.
  • It doesn't indicate whether the process was successful or not. Perhaps it should return a boolean value indicating success or failure, similar to wp_trash_comment?

I haven't actually tested it, but it should be something like this:

/**
 * Delete all of a comment's descendants.
 *
 * @since 6.9.0
 *
 * @param int $comment_id The comment ID.
 * @return bool True on success, false on failure.
 */
function wp_trash_comment_descendants( $comment_id ) {
	$comment = get_comment( $comment_id );
	if ( ! $comment ) {
		return false;
	}

	$comments = $comment->get_children(
		array(
			'format' => 'flat',
			'status' => 'all',
		)
	);

	$success = true;
	foreach ( $descendants as $child ) {
		if ( ! wp_trash_comment( $child->comment_ID ) ) {
			$success = false;
		}
	}

	return $success;
}

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.

Nested notes are not deleted or trashed when parent note is

3 participants