diff --git a/lib/endpoints/class-wp-rest-users-controller.php b/lib/endpoints/class-wp-rest-users-controller.php index d2361bb5c1..6d4297b5c2 100755 --- a/lib/endpoints/class-wp-rest-users-controller.php +++ b/lib/endpoints/class-wp-rest-users-controller.php @@ -25,11 +25,7 @@ public function register_routes() { 'methods' => WP_REST_Server::CREATABLE, 'callback' => array( $this, 'create_item' ), 'permission_callback' => array( $this, 'create_item_permissions_check' ), - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array( - 'password' => array( - 'required' => true, - ), - ) ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), ), 'schema' => array( $this, 'get_public_item_schema' ), ) ); @@ -46,9 +42,7 @@ public function register_routes() { 'methods' => WP_REST_Server::EDITABLE, 'callback' => array( $this, 'update_item' ), 'permission_callback' => array( $this, 'update_item_permissions_check' ), - 'args' => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), array( - 'password' => array(), - ) ), + 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), ), array( 'methods' => WP_REST_Server::DELETABLE, @@ -747,6 +741,12 @@ public function get_item_schema() { 'type' => 'array', 'context' => array( 'edit' ), ), + 'password' => array( + 'description' => __( 'Password for the resource (never included).' ), + 'type' => 'string', + 'context' => array(), // Password is never displayed + 'required' => true, + ), 'capabilities' => array( 'description' => __( 'All capabilities assigned to the resource.' ), 'type' => 'object', diff --git a/tests/test-rest-users-controller.php b/tests/test-rest-users-controller.php index 5b917605ea..ce1aa76320 100644 --- a/tests/test-rest-users-controller.php +++ b/tests/test-rest-users-controller.php @@ -919,7 +919,7 @@ public function test_get_item_schema() { $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertEquals( 16, count( $properties ) ); + $this->assertEquals( 17, count( $properties ) ); $this->assertArrayHasKey( 'avatar_urls', $properties ); $this->assertArrayHasKey( 'capabilities', $properties ); $this->assertArrayHasKey( 'description', $properties ); @@ -933,6 +933,7 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'nickname', $properties ); $this->assertArrayHasKey( 'registered_date', $properties ); $this->assertArrayHasKey( 'slug', $properties ); + $this->assertArrayHasKey( 'password', $properties ); $this->assertArrayHasKey( 'url', $properties ); $this->assertArrayHasKey( 'username', $properties ); $this->assertArrayHasKey( 'roles', $properties ); @@ -1051,6 +1052,8 @@ protected function check_user_data( $user, $data, $context ) { $this->assertArrayNotHasKey( 'username', $data ); } + $this->assertArrayNotHasKey( 'password', $data ); + } protected function check_get_user_response( $response, $context = 'view' ) {