Skip to content

Commit

Permalink
REST API: Cast revision author ID to int.
Browse files Browse the repository at this point in the history
The `post_author` field is a string internally, but we need to cast it to an integer in the REST API.  This was already done for posts, but not for revisions.  The field is already declared as an integer in both controllers.

Fixes #39871.


git-svn-id: https://develop.svn.wordpress.org/trunk@40063 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
nylen committed Feb 16, 2017
1 parent beb9d91 commit 392fd09
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function prepare_item_for_response( $post, $request ) {
$data = array();

if ( ! empty( $schema['properties']['author'] ) ) {
$data['author'] = $post->post_author;
$data['author'] = (int) $post->post_author;
}

if ( ! empty( $schema['properties']['date'] ) ) {
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/tests/rest-api/rest-revisions-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public static function wpSetUpBeforeClass( $factory ) {
'role' => 'contributor',
) );

wp_set_current_user( self::$editor_id );
wp_update_post( array( 'post_content' => 'This content is better.', 'ID' => self::$post_id ) );
wp_update_post( array( 'post_content' => 'This content is marvelous.', 'ID' => self::$post_id ) );
wp_set_current_user( 0 );
}

public static function wpTearDownAfterClass() {
Expand Down Expand Up @@ -136,6 +138,7 @@ public function test_get_item() {
);
$data = $response->get_data();
$this->assertEqualSets( $fields, array_keys( $data ) );
$this->assertSame( self::$editor_id, $data['author'] );
}

public function test_get_item_embed_context() {
Expand Down

0 comments on commit 392fd09

Please sign in to comment.