REST API: Check read permissions on posts when viewing comments.

With a few tests for getting / creating comments to reflect core behaviour.

Props timmyc.

git-svn-id: https://develop.svn.wordpress.org/trunk@39295 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Hoyle
2016-11-18 19:06:26 +00:00
parent b34803f431
commit db07183b6f
2 changed files with 77 additions and 0 deletions

View File

@@ -1454,6 +1454,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
*/
protected function check_read_post_permission( $post ) {
$posts_controller = new WP_REST_Posts_Controller( $post->post_type );
$post_type = get_post_type_object( $post->post_type );
if ( post_password_required( $post ) ) {
return current_user_can( $post_type->cap->edit_post, $post->ID );
}
return $posts_controller->check_read_permission( $post );
}