Commit c2543452dc for wordpress.org
commit c2543452dcc557cbd195bb96954cdc3dfae663d1
Author: westonruter <westonruter@git.wordpress.org>
Date: Wed Sep 23 02:35:50 2026 +0000
Comments: Skip descendant comments that no longer exist.
In `WP_Comment_Query::fill_descendants()`, the return value of `get_comment()` was added to the results for each descendant ID without being checked. When a descendant ID from the cached parent-child relationships no longer resolves to a comment, `get_comment()` returns `null`. For a `threaded` query, as used by `comments_template()` when threaded comments are enabled, this caused a fatal error from calling `populated_children()` on `null`; for a `flat` query, the `null` was returned among the comments for the caller to trip over. Such descendants are now skipped.
Developed in https://github.com/WordPress/wordpress-develop/pull/13643.
Follow-up to r34546.
Props josephscott, westonruter, mukesh27.
See #65817.
Fixes #66151.
Built from https://develop.svn.wordpress.org/trunk@63886
git-svn-id: http://core.svn.wordpress.org/trunk@63058 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/class-wp-comment-query.php b/wp-includes/class-wp-comment-query.php
index f80864d31c..1147446bb7 100644
--- a/wp-includes/class-wp-comment-query.php
+++ b/wp-includes/class-wp-comment-query.php
@@ -1119,7 +1119,10 @@ class WP_Comment_Query {
// Assemble a flat array of all comments + descendants.
$all_comments = $comments;
foreach ( $descendant_ids as $descendant_id ) {
- $all_comments[] = get_comment( $descendant_id );
+ $descendant = get_comment( $descendant_id );
+ if ( $descendant instanceof WP_Comment ) {
+ $all_comments[] = $descendant;
+ }
}
// If a threaded representation was requested, build the tree.
diff --git a/wp-includes/version.php b/wp-includes/version.php
index c7bc01e420..aead9e184d 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-alpha-63885';
+$wp_version = '7.2-alpha-63886';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.