-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Trash child notes when a top level note is trashed #10496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Trash child notes when a top level note is trashed #10496
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
desrosj
left a comment
There was a problem hiding this 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 ) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @since 6.9.1 | |
| * @since 6.9.0 |
| * | ||
| * @covers ::wp_trash_comment | ||
| */ | ||
| public function test_wp_trash_comment_does_not_trash_child_comments() { |
There was a problem hiding this comment.
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.
|
I think there are two areas for improvement in the
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;
} |
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.