From 804bb2031643b19a1787442f220a5e2419e2a0d2 Mon Sep 17 00:00:00 2001
From: Himani <himaniwork3010@gmail.com>
Date: Sun, 24 Nov 2019 19:35:39 +0530
Subject: [PATCH] Fix: #42238 Notice when Rest Comments controller is checking
 permission for a non existent post type

---
 .../rest-api/endpoints/class-wp-rest-comments-controller.php  | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
index f673450d41..c9dda586fa 100644
--- a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
+++ b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
@@ -1584,6 +1584,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
 	protected function check_read_post_permission( $post, $request ) {
 		$posts_controller = new WP_REST_Posts_Controller( $post->post_type );
 		$post_type        = get_post_type_object( $post->post_type );
+		// Return false if custom post type doesn't exist
+		if(is_null($post_type)) {
+			return false;
+		}
 
 		$has_password_filter = false;
 
-- 
2.20.0.windows.1

