From 7660fcda6112bbd0d833cd804b43b198125de6f0 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Fri, 3 Jan 2020 18:44:03 +0000 Subject: [PATCH] REST API: Short-circuit comment controller permissions check if commented-upon post type does not exist. Props imani3011, dragosh635, subrataemfluence, timothyblynjacobs. Fixes #42238. Built from https://develop.svn.wordpress.org/trunk@47036 git-svn-id: http://core.svn.wordpress.org/trunk@46836 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-comments-controller.php | 8 +++++++- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) 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 ca5336f5aa..e05f9802ea 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 @@ -1592,7 +1592,13 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { * @return bool Whether post can be read. */ protected function check_read_post_permission( $post, $request ) { - $post_type = get_post_type_object( $post->post_type ); + $post_type = get_post_type_object( $post->post_type ); + + // Return false if custom post type doesn't exist + if ( ! $post_type ) { + return false; + } + $posts_controller = $post_type->get_rest_controller(); // Ensure the posts controller is specifically a WP_REST_Posts_Controller instance diff --git a/wp-includes/version.php b/wp-includes/version.php index ccf328d84e..9fc7cdbe63 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-47035'; +$wp_version = '5.4-alpha-47036'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.