REST API: Cast revision author ID to int.

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
This commit is contained in:
James Nylen 2017-02-16 20:08:23 +00:00
parent beb9d91279
commit 392fd09f82
2 changed files with 4 additions and 1 deletions

View File

@ -344,7 +344,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
$data = array(); $data = array();
if ( ! empty( $schema['properties']['author'] ) ) { if ( ! empty( $schema['properties']['author'] ) ) {
$data['author'] = $post->post_author; $data['author'] = (int) $post->post_author;
} }
if ( ! empty( $schema['properties']['date'] ) ) { if ( ! empty( $schema['properties']['date'] ) ) {

View File

@ -27,8 +27,10 @@ class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase
'role' => 'contributor', '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 better.', 'ID' => self::$post_id ) );
wp_update_post( array( 'post_content' => 'This content is marvelous.', '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() { public static function wpTearDownAfterClass() {
@ -136,6 +138,7 @@ class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase
); );
$data = $response->get_data(); $data = $response->get_data();
$this->assertEqualSets( $fields, array_keys( $data ) ); $this->assertEqualSets( $fields, array_keys( $data ) );
$this->assertSame( self::$editor_id, $data['author'] );
} }
public function test_get_item_embed_context() { public function test_get_item_embed_context() {