Make WordPress Core


Ignore:
Timestamp:
11/20/2025 01:58:35 PM (9 months ago)
Author:
wildworks
Message:

Notes: trash (or delete) child notes when parent is deleted.

Ensure that when a top level note is trashed (or deleted), all of its replies (children) are also trashed or deleted. If EMPTY_TRASH_DAYS is 0, notes are deleted immediately; otherwise they are marked as trash for later cleanup.

Reviewed by wildworks.
Merges [61248] to the 6.9 branch.

Props adamsilverstein, desrosj, wildworks, mamaduka, karthickmurugan, jeffpaul, shailu25.
See #64240.

Location:
branches/6.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.9

  • branches/6.9/src/wp-includes/comment.php

    r61199 r61274  
    15751575 *
    15761576 * @since 2.9.0
     1577 * @since 6.9.0 Any child notes are deleted when deleting a note.
    15771578 *
    15781579 * @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
     
    15811582function wp_trash_comment( $comment_id ) {
    15821583        if ( ! EMPTY_TRASH_DAYS ) {
    1583                 return wp_delete_comment( $comment_id, true );
     1584                $comment = get_comment( $comment_id );
     1585                $success = wp_delete_comment( $comment_id, true );
     1586
     1587                if ( ! $success ) {
     1588                        return false;
     1589                }
     1590
     1591                // Also delete children of top level 'note' type comments.
     1592                if ( $comment && 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
     1593                        $children = $comment->get_children(
     1594                                array(
     1595                                        'fields' => 'ids',
     1596                                        'status' => 'all',
     1597                                        'type'   => 'note',
     1598                                )
     1599                        );
     1600
     1601                        foreach ( $children as $child_id ) {
     1602                                if ( ! wp_delete_comment( $child_id, true ) ) {
     1603                                        $success = false;
     1604                                }
     1605                        }
     1606                }
     1607
     1608                return $success;
    15841609        }
    15851610
     
    16161641                 */
    16171642                do_action( 'trashed_comment', $comment->comment_ID, $comment );
     1643
     1644                // For top level 'note' type comments, also trash children.
     1645                if ( 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
     1646                        $children = $comment->get_children(
     1647                                array(
     1648                                        'fields' => 'ids',
     1649                                        'status' => 'all',
     1650                                        'type'   => 'note',
     1651                                )
     1652                        );
     1653
     1654                        $success = true;
     1655                        foreach ( $children as $child_id ) {
     1656                                if ( ! wp_trash_comment( $child_id ) ) {
     1657                                        $success = false;
     1658                                }
     1659                        }
     1660                        return $success;
     1661                }
    16181662
    16191663                return true;
Note: See TracChangeset for help on using the changeset viewer.