@@ -1581,8 +1581,27 @@ function wp_delete_comment( $comment_id, $force_delete = false ) {
15811581 */
15821582function wp_trash_comment ( $ comment_id ) {
15831583 if ( ! EMPTY_TRASH_DAYS ) {
1584- wp_trash_note_descendants ( $ comment_id );
1585- return wp_delete_comment ( $ comment_id , true );
1584+ $ comment = get_comment ( $ comment_id );
1585+ $ success = wp_delete_comment ( $ comment_id , true );
1586+ // Also delete descendants of top level 'note' type comments.
1587+ if ( $ comment && 'note ' === $ comment ->comment_type && 0 === (int ) $ comment ->comment_parent ) {
1588+ $ children = $ comment ->get_children (
1589+ array (
1590+ 'fields ' => 'ids ' ,
1591+ 'status ' => 'all ' ,
1592+ 'type ' => 'note ' ,
1593+ )
1594+ );
1595+
1596+ $ success = true ;
1597+ foreach ( $ children as $ child_id ) {
1598+ if ( ! wp_delete_comment ( $ child_id , true ) ) {
1599+ $ success = false ;
1600+ }
1601+ }
1602+ }
1603+
1604+ return $ success ;
15861605 }
15871606
15881607 $ comment = get_comment ( $ comment_id );
@@ -1618,9 +1637,23 @@ function wp_trash_comment( $comment_id ) {
16181637 */
16191638 do_action ( 'trashed_comment ' , $ comment ->comment_ID , $ comment );
16201639
1621- // For top level 'note' type comments, also trash any children as well.
1640+ // For top level 'note' type comments, also trash any descendants as well.
16221641 if ( 'note ' === $ comment ->comment_type && 0 === (int ) $ comment ->comment_parent ) {
1623- wp_trash_note_descendants ( $ comment ->comment_ID );
1642+ $ children = $ comment ->get_children (
1643+ array (
1644+ 'fields ' => 'ids ' ,
1645+ 'status ' => 'all ' ,
1646+ 'type ' => 'note ' ,
1647+ )
1648+ );
1649+
1650+ $ success = true ;
1651+ foreach ( $ children as $ child_id ) {
1652+ if ( ! wp_trash_comment ( $ child_id ) ) {
1653+ $ success = false ;
1654+ }
1655+ }
1656+ return $ success ;
16241657 }
16251658
16261659 return true ;
@@ -1629,43 +1662,6 @@ function wp_trash_comment( $comment_id ) {
16291662 return false ;
16301663}
16311664
1632- /**
1633- * Trash all of a note's descendants or delete immaediately if EMPTY_TRASH_DAYS is 0.
1634- *
1635- * @since 6.9.0
1636- *
1637- * @param int $comment_id The comment ID.
1638- * @return bool Whether the descendants were successfully trashed.
1639- */
1640- function wp_trash_note_descendants ( $ comment_id ) {
1641- $ comment = get_comment ( $ comment_id );
1642- if ( ! $ comment ) {
1643- return false ;
1644- }
1645- $ children = $ comment ->get_children (
1646- array (
1647- 'fields ' => 'ids ' ,
1648- 'status ' => 'all ' ,
1649- 'type ' => 'note ' ,
1650- )
1651- );
1652-
1653- $ success = true ;
1654- foreach ( $ children as $ child_id ) {
1655- if ( ! EMPTY_TRASH_DAYS ) {
1656- // If trash is disabled, delete the comment permanently.
1657- if ( ! wp_delete_comment ( $ child_id , true ) ) {
1658- $ success = false ;
1659- }
1660- } else {
1661- if ( ! wp_trash_comment ( $ child_id ) ) {
1662- $ success = false ;
1663- }
1664- }
1665- }
1666- return $ success ;
1667- }
1668-
16691665/**
16701666 * Removes a comment from the Trash
16711667 *
0 commit comments