diff --git a/projects/plugins/jetpack/changelog/fix-jetpack-comment-endpoint-warnings b/projects/plugins/jetpack/changelog/fix-jetpack-comment-endpoint-warnings new file mode 100644 index 0000000000000..cd8d8e645371b --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-jetpack-comment-endpoint-warnings @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +REST API: Avoid PHP warnings in comment endpoint when the parent comment does not exist. diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-comment-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-comment-endpoint.php index 73666bdceeebc..d7c12196f3287 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-comment-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-comment-endpoint.php @@ -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' ),