REST API: Include the `status` property in `view` context responses from the Posts endpoints.

Previously the status for a Post (or other post_types) was only exposed under the `edit` context, which doesn't really make much sense considering we support querying by post status without authentication. Originally introduced in v2.0 beta 1: 69f617d749 without any explanation in the commit message.

Props dhanendran, jnylen0, rachelbaker.
Fixes #39466.


git-svn-id: https://develop.svn.wordpress.org/trunk@40080 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
rachelbaker 2017-02-19 04:31:12 +00:00
parent 127f243bfe
commit bf6a689c65
3 changed files with 8 additions and 2 deletions

View File

@ -1767,7 +1767,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
'description' => __( 'A named status for the object.' ),
'type' => 'string',
'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ),
'context' => array( 'edit' ),
'context' => array( 'view', 'edit' ),
),
'type' => array(
'description' => __( 'Type of Post for the object.' ),

View File

@ -134,11 +134,11 @@ abstract class WP_Test_REST_Post_Type_Controller_Testcase extends WP_Test_REST_C
$this->assertFalse( isset( $data['excerpt'] ) );
}
$this->assertEquals( $post->post_status, $data['status'] );
$this->assertEquals( $post->guid, $data['guid']['rendered'] );
if ( 'edit' === $context ) {
$this->assertEquals( $post->guid, $data['guid']['raw'] );
$this->assertEquals( $post->post_status, $data['status'] );
if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) {
$this->assertNull( $data['date_gmt'] );

View File

@ -3384,6 +3384,7 @@ mockedApiResponse.PostsCollection = [
"modified": "2017-02-14T00:00:00",
"modified_gmt": "2017-02-14T00:00:00",
"slug": "restapi-client-fixture-post",
"status": "publish",
"type": "post",
"link": "http://example.org/?p=3",
"title": {
@ -3474,6 +3475,7 @@ mockedApiResponse.PostModel = {
"modified": "2017-02-14T00:00:00",
"modified_gmt": "2017-02-14T00:00:00",
"slug": "restapi-client-fixture-post",
"status": "publish",
"type": "post",
"link": "http://example.org/?p=3",
"title": {
@ -3552,6 +3554,7 @@ mockedApiResponse.PagesCollection = [
"modified": "2017-02-14T00:00:00",
"modified_gmt": "2017-02-14T00:00:00",
"slug": "restapi-client-fixture-page",
"status": "publish",
"type": "page",
"link": "http://example.org/?page_id=5",
"title": {
@ -3626,6 +3629,7 @@ mockedApiResponse.PageModel = {
"modified": "2017-02-14T00:00:00",
"modified_gmt": "2017-02-14T00:00:00",
"slug": "restapi-client-fixture-page",
"status": "publish",
"type": "page",
"link": "http://example.org/?page_id=5",
"title": {
@ -3700,6 +3704,7 @@ mockedApiResponse.MediaCollection = [
"modified": "2017-02-14T00:00:00",
"modified_gmt": "2017-02-14T00:00:00",
"slug": "restapi-client-fixture-attachment",
"status": "inherit",
"type": "attachment",
"link": "http://example.org/?attachment_id=7",
"title": {
@ -3758,6 +3763,7 @@ mockedApiResponse.MediaModel = {
"modified": "2017-02-14T00:00:00",
"modified_gmt": "2017-02-14T00:00:00",
"slug": "restapi-client-fixture-attachment",
"status": "inherit",
"type": "attachment",
"link": "http://example.org/?attachment_id=7",
"title": {