Skip to content

Commit

Permalink
Jetpack: Fix REST API warnings from Comments endpoint
Browse files Browse the repository at this point in the history
There are two bugs involved here:

* The Subscriptions block is trying to hide comments by returning
  empty-string from the 'get_comment' filter, but that filter must
  return a WP_Comment object. Not even null would be right.
* The REST API endpoint isn't checking for if `get_comment()` on the
  parent comment ID returns null.

This fixes the second; I don't know what would be correct to fix the
first.
  • Loading branch information
anomiex committed Aug 27, 2024
1 parent 6e57285 commit 976cdae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

REST API: Avoid PHP warnings in comment endpoint when the parent comment does not exist.
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public function get_comment( $comment_id, $context ) {
$response[ $key ] = (string) $status;
break;
case 'parent': // May be object or false.
if ( $comment->comment_parent ) {
$parent = get_comment( $comment->comment_parent );
$parent = $comment->comment_parent ? get_comment( $comment->comment_parent ) : null;
if ( $parent ) {
$response[ $key ] = (object) array(
'ID' => (int) $parent->comment_ID,
'type' => (string) ( $parent->comment_type ? $parent->comment_type : 'comment' ),
Expand Down

0 comments on commit 976cdae

Please sign in to comment.