From 7be9593b68b4ada1c8bf0da075ca3b69a6ce1346 Mon Sep 17 00:00:00 2001 From: Rachel Baker Date: Sun, 19 Feb 2017 03:18:38 +0000 Subject: [PATCH] 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. Props jnylen0. Merges [40063] to the 4.7 branch. Fixes #39871. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@40078 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-api/endpoints/class-wp-rest-revisions-controller.php | 2 +- tests/phpunit/tests/rest-api/rest-revisions-controller.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php index c38bd45928..d3f665de12 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php @@ -344,7 +344,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller { $data = array(); if ( ! empty( $schema['properties']['author'] ) ) { - $data['author'] = $post->post_author; + $data['author'] = (int) $post->post_author; } if ( ! empty( $schema['properties']['date'] ) ) { diff --git a/tests/phpunit/tests/rest-api/rest-revisions-controller.php b/tests/phpunit/tests/rest-api/rest-revisions-controller.php index 3c88c6fa0e..455700438b 100644 --- a/tests/phpunit/tests/rest-api/rest-revisions-controller.php +++ b/tests/phpunit/tests/rest-api/rest-revisions-controller.php @@ -27,8 +27,10 @@ class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase '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() { @@ -136,6 +138,7 @@ class WP_Test_REST_Revisions_Controller extends WP_Test_REST_Controller_Testcase ); $data = $response->get_data(); $this->assertEqualSets( $fields, array_keys( $data ) ); + $this->assertSame( self::$editor_id, $data['author'] ); } public function test_get_item_embed_context() {