-
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.
|
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;
} |
|
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. |
|
@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 |
Co-authored-by: Jonathan Desrosiers <[email protected]>
Co-authored-by: Jonathan Desrosiers <[email protected]>
@desrosj added support for delete when EMPTY_TRASH_DAYS is 0 in f5c64ba |
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. |
|
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. |
@t-hamano I have inlined the functionality in 5aa9e22 to avoid the new function. We can clean this up in a future release. |
t-hamano
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.
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.
Co-authored-by: Aki Hamano <[email protected]>
I created a Trac ticket to cover this PR and linked in the description. |
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.
Few follow up questions!
|
@desrosj Thanks for the feedback which I have addressed. |
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.