From a36830c4cb9b8d18b6bc2fc431ff64c1a8cbc6f5 Mon Sep 17 00:00:00 2001 From: desrosj Date: Tue, 11 Dec 2018 22:30:24 +0000 Subject: [PATCH] REST API: Enable users with read_private_posts to query for them. An authorized request with the read_private_posts capability for a post type should be able to GET /wp/v2/posts for posts of status=private. This query is further sanity-checked by WP_REST_Posts_Controller->check_read_permission(), which is unchanged. Props rachelbaker, soulseekah, twoelevenjay. Moves [43694] from the 5.0 branch to trunk. Fixes #43701. Built from https://develop.svn.wordpress.org/trunk@43979 git-svn-id: http://core.svn.wordpress.org/trunk@43811 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/rest-api.php | 2 +- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 2 +- wp-includes/version.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index 0cce9fa62f..35bab60712 100644 --- a/wp-includes/rest-api.php +++ b/wp-includes/rest-api.php @@ -990,7 +990,7 @@ function rest_sanitize_boolean( $value ) { } // Everything else will map nicely to boolean. - return (boolean) $value; + return (bool) $value; } /** diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index bff977e40c..875b0518eb 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -2509,7 +2509,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $post_type_obj = get_post_type_object( $this->post_type ); - if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { + if ( current_user_can( $post_type_obj->cap->edit_posts ) || 'private' === $status && current_user_can( $post_type_obj->cap->read_private_posts ) ) { $result = rest_validate_request_arg( $status, $request, $parameter ); if ( is_wp_error( $result ) ) { return $result; diff --git a/wp-includes/version.php b/wp-includes/version.php index 9f984ff861..23f2d15481 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-43978'; +$wp_version = '5.1-alpha-43979'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.