Commit f5268cfbd5 for wordpress.org
commit f5268cfbd5361508b32e01897b4a01eed1a1e79d
Author: wildworks <wildworks@git.wordpress.org>
Date: Fri Oct 23 03:14:53 2026 +0000
Comments: Restore child notes trashed with their parent note.
Restoring a top-level note from the Trash now also restores the child notes that were trashed along with it. Child notes the user trashed individually before trashing the parent stay in the Trash.
Developed in: https://github.com/WordPress/wordpress-develop/pull/14044
Props wildworks, mukesh27, peterwilsoncc.
Fixes #66255.
Built from https://develop.svn.wordpress.org/trunk@64684
git-svn-id: http://core.svn.wordpress.org/trunk@63834 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/comment.php b/wp-includes/comment.php
index c5d576e773..b6847266eb 100644
--- a/wp-includes/comment.php
+++ b/wp-includes/comment.php
@@ -1676,6 +1676,7 @@ function wp_delete_comment( $comment_id, $force_delete = false ) {
* @since 2.9.0
* @since 6.9.0 Any child notes are deleted when deleting a note.
* @since 7.2.0 A note's reactions are trashed along with it.
+ * @since 7.2.0 The child notes trashed along with a note are recorded, so that they can be restored with it.
*
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
* @return bool True on success, false on failure.
@@ -1748,8 +1749,7 @@ function wp_trash_comment( $comment_id ) {
* own reactions along through this same branch.
*
* Restoring the note does not bring its reactions back:
- * wp_untrash_comment() restores no children of any type, so restoring
- * children is left to a cascade that covers every child type together.
+ * wp_untrash_comment() only restores the child notes recorded below.
*/
if ( 'note' === $comment->comment_type ) {
$reaction_ids = get_comments(
@@ -1776,6 +1776,22 @@ function wp_trash_comment( $comment_id ) {
)
);
+ // Skip children already in the Trash, so that they are not restored with the parent.
+ $children = array_values(
+ array_filter(
+ array_map( 'intval', $children ),
+ static function ( $child_id ) {
+ return 'trash' !== wp_get_comment_status( $child_id );
+ }
+ )
+ );
+
+ // Record the children trashed along with the parent, so that they can be restored with it.
+ delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_children' );
+ if ( $children ) {
+ add_comment_meta( $comment->comment_ID, '_wp_trash_meta_children', $children );
+ }
+
$success = true;
foreach ( $children as $child_id ) {
if ( ! wp_trash_comment( $child_id ) ) {
@@ -1795,6 +1811,7 @@ function wp_trash_comment( $comment_id ) {
* Removes a comment from the Trash
*
* @since 2.9.0
+ * @since 7.2.0 Any child notes trashed along with a note are restored when restoring the note.
*
* @param int|WP_Comment $comment_id Comment ID or WP_Comment object.
* @return bool True on success, false on failure.
@@ -1836,6 +1853,36 @@ function wp_untrash_comment( $comment_id ) {
*/
do_action( 'untrashed_comment', $comment->comment_ID, $comment );
+ // For top level 'note' type comments, also restore the children trashed along with it.
+ if ( 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
+ $children = get_comment_meta( $comment->comment_ID, '_wp_trash_meta_children', true );
+ delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_children' );
+
+ if ( ! is_array( $children ) ) {
+ return true;
+ }
+
+ $success = true;
+ foreach ( $children as $child_id ) {
+ $child = get_comment( (int) $child_id );
+
+ // Skip children that have been deleted, moved, or restored in the meantime.
+ if (
+ ! $child ||
+ 'note' !== $child->comment_type ||
+ (int) $child->comment_parent !== (int) $comment->comment_ID ||
+ 'trash' !== wp_get_comment_status( $child )
+ ) {
+ continue;
+ }
+
+ if ( ! wp_untrash_comment( $child ) ) {
+ $success = false;
+ }
+ }
+ return $success;
+ }
+
return true;
}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 7cf060120c..8516225007 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-beta1-64683';
+$wp_version = '7.2-beta1-64684';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.