Skip to content

Commit 3912b78

Browse files
Trash child notes when a top level note is trashed
1 parent 328ab83 commit 3912b78

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/wp-includes/comment.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,7 @@ function wp_delete_comment( $comment_id, $force_delete = false ) {
15741574
* If Trash is disabled, comment is permanently deleted.
15751575
*
15761576
* @since 2.9.0
1577+
* @since 6.9.1 Any child notes are deleted when deleting a note.
15771578
*
15781579
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
15791580
* @return bool True on success, false on failure.
@@ -1616,12 +1617,36 @@ function wp_trash_comment( $comment_id ) {
16161617
*/
16171618
do_action( 'trashed_comment', $comment->comment_ID, $comment );
16181619

1620+
// For top level 'note' type comments, also trash any children as well.
1621+
if ( 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
1622+
wp_trash_comment_children( $comment->comment_ID );
1623+
}
1624+
16191625
return true;
16201626
}
16211627

16221628
return false;
16231629
}
16241630

1631+
/**
1632+
* Delete all of a note's children (replies).
1633+
*
1634+
* @since 6.9.1
1635+
*
1636+
* @param int $comment_id The comment ID.
1637+
*/
1638+
function wp_trash_comment_children( $comment_id ) {
1639+
$children = get_comments( array(
1640+
'parent' => $comment_id,
1641+
'status' => 'all',
1642+
'type' => 'note',
1643+
'fields' => 'ids',
1644+
) );
1645+
foreach ( $children as $child_id ) {
1646+
wp_trash_comment( $child_id );
1647+
}
1648+
}
1649+
16251650
/**
16261651
* Removes a comment from the Trash
16271652
*

0 commit comments

Comments
 (0)