Skip to content

Conversation

@adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Nov 10, 2025

Fixes WordPress/gutenberg#72862

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


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.

@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;
}

@adamsilverstein
Copy link
Member Author

adamsilverstein commented Nov 11, 2025

Ah! I specifically excluded grandchildren because that's not possible currently with notes. Good idea though. We can add to make this more robust and usable for other comment types.

@t-hamano
Copy link
Contributor

@adamsilverstein I've thought about it again, but since RC1 is about to be released, we probably can't add new functions right now. Instead of creating a new function, could we just move the logic into the existing wp_trash_comment function?

@adamsilverstein
Copy link
Member Author

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.

@desrosj added support for delete when EMPTY_TRASH_DAYS is 0 in f5c64ba

@adamsilverstein
Copy link
Member Author

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

@t-hamano I addressed this feedback in 4c0cc8a

@adamsilverstein
Copy link
Member Author

I've thought about it again, but since RC1 is about to be released, we probably can't add new functions right now. Instead of creating a new function, could we just move the logic into the existing wp_trash_comment function?

Now I am calling the function twice that will be a bit messy. Is there a specific prohibition to adding functions in RC? Since we are addressing an issue with a major new feature for this release, we can still make this type of change?

That said, I am perfectly fine punting this change to a 6.9.1 release.

@t-hamano
Copy link
Contributor

Strictly speaking, I think no new features can be added after Beta1. However, since the notes feature is new in 6.9, that rule will likely be a little more flexible.

That said, adding a new function comes with the responsibility of maintaining it indefinitely. Other issues related to the notes feature may arise in the future. Until those issues are resolved and the feature is stable, I prefer not to create any new functions if possible.

@adamsilverstein
Copy link
Member Author

I've thought about it again, but since RC1 is about to be released, we probably can't add new functions right now. Instead of creating a new function, could we just move the logic into the existing wp_trash_comment function?

@t-hamano I have inlined the functionality in 5aa9e22 to avoid the new function. We can clean this up in a future release.

@adamsilverstein
Copy link
Member Author

adamsilverstein commented Nov 11, 2025

Added
Test that note and descendants are deleted when EMPTY_TRASH_DAYS is 0 - fc017d8
Test that all descendants including grandchildren are trashed dcb4fa3

These tests were removed.

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

I've actually tested this PR by monitoring the database, and everything seems to be working as expected. Let's consider removing the grandchild notes in the future.

@desrosj @Mamaduka, I think backport commits after RC require approval from two contributors. I would appreciate it if you could check this PR.

@adamsilverstein
Copy link
Member Author

This pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac.

I created a Trac ticket to cover this PR and linked in the description.

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.

Few follow up questions!

@adamsilverstein
Copy link
Member Author

@desrosj Thanks for the feedback which I have addressed.

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

4 participants