From 855a29ccbf8607a7194cca3d1d2f33d4fa74f84a Mon Sep 17 00:00:00 2001 From: Rachel Baker Date: Thu, 27 Oct 2016 14:36:49 +0000 Subject: [PATCH] REST API: Remove the Location header redirect for the /users/me endpoint. Props youknowriad jnylen0. Fixes #38521. git-svn-id: https://develop.svn.wordpress.org/trunk@38980 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-api/endpoints/class-wp-rest-users-controller.php | 2 -- tests/phpunit/tests/rest-api/rest-users-controller.php | 8 +++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index 12a13055a2..9430438b66 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -288,8 +288,6 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $user = wp_get_current_user(); $response = $this->prepare_item_for_response( $user, $request ); $response = rest_ensure_response( $response ); - $response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $current_user_id ) ) ); - $response->set_status( 302 ); return $response; } diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index f2131d4806..0eb83a3b8f 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -635,11 +635,13 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { $request = new WP_REST_Request( 'GET', '/wp/v2/users/me' ); $response = $this->server->dispatch( $request ); - $this->assertEquals( 302, $response->get_status() ); + $this->assertEquals( 200, $response->get_status() ); $headers = $response->get_headers(); - $this->assertArrayHasKey( 'Location', $headers ); - $this->assertEquals( rest_url( 'wp/v2/users/' . self::$user ), $headers['Location'] ); + $this->assertArrayNotHasKey( 'Location', $headers ); + + $links = $response->get_links(); + $this->assertEquals( rest_url( 'wp/v2/users/' . self::$user ), $links['self'][0]['href'] ); } public function test_get_current_user_without_permission() {