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 63fb4e9..adb7db5 100644
a
|
b
|
class WP_REST_Users_Controller extends WP_REST_Controller { |
471 | 471 | } |
472 | 472 | |
473 | 473 | $user = $this->prepare_item_for_database( $request ); |
| 474 | |
| 475 | if ( ! isset( $user->user_pass ) ) { |
| 476 | $user->user_pass = wp_generate_password( 24 ); |
| 477 | } |
474 | 478 | |
475 | 479 | if ( is_multisite() ) { |
476 | 480 | $ret = wpmu_validate_user_signup( $user->user_login, $user->user_email ); |
… |
… |
class WP_REST_Users_Controller extends WP_REST_Controller { |
1250 | 1254 | 'description' => __( 'Password for the user (never included).' ), |
1251 | 1255 | 'type' => 'string', |
1252 | 1256 | 'context' => array(), // Password is never displayed. |
1253 | | 'required' => true, |
1254 | 1257 | 'arg_options' => array( |
1255 | 1258 | 'sanitize_callback' => array( $this, 'check_user_password' ), |
1256 | 1259 | ), |
diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php
index 062a90e..a41c475 100644
a
|
b
|
class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { |
909 | 909 | $this->assertEquals( array( 'editor' ), $data['roles'] ); |
910 | 910 | $this->check_add_edit_user_response( $response ); |
911 | 911 | } |
| 912 | |
| 913 | public function test_create_item_generates_password_if_omitted() { |
| 914 | |
| 915 | $this->allow_user_to_manage_multisite(); |
| 916 | wp_set_current_user( self::$user ); |
| 917 | |
| 918 | $params = array( |
| 919 | 'username' => 'testuser', |
| 920 | 'email' => 'test@example.com', |
| 921 | 'name' => 'Test User', |
| 922 | 'nickname' => 'testuser', |
| 923 | 'slug' => 'test-user', |
| 924 | ); |
| 925 | |
| 926 | $request = new WP_REST_Request( 'POST', '/wp/v2/users' ); |
| 927 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
| 928 | $request->set_body_params( $params ); |
| 929 | |
| 930 | $response = $this->server->dispatch( $request ); |
| 931 | $data = $response->get_data(); |
| 932 | |
| 933 | $user = get_userdata( $data['id'] ); |
| 934 | $this->assertNotEmpty( $user ); |
| 935 | $this->assertNotEmpty( $user->user_pass ); |
| 936 | $this->check_add_edit_user_response( $response ); |
| 937 | } |
912 | 938 | |
| 939 | public function test_create_item_empty_password() { |
| 940 | |
| 941 | $this->allow_user_to_manage_multisite(); |
| 942 | wp_set_current_user( self::$user ); |
| 943 | |
| 944 | $params = array( |
| 945 | 'username' => 'testuser', |
| 946 | 'password' => '', |
| 947 | 'email' => 'test@example.com', |
| 948 | 'name' => 'Test User', |
| 949 | 'nickname' => 'testuser', |
| 950 | 'slug' => 'test-user', |
| 951 | ); |
| 952 | |
| 953 | $request = new WP_REST_Request( 'POST', '/wp/v2/users' ); |
| 954 | $request->add_header( 'content-type', 'application/x-www-form-urlencoded' ); |
| 955 | $request->set_body_params( $params ); |
| 956 | |
| 957 | $response = $this->server->dispatch( $request ); |
| 958 | $this->assertErrorResponse( 'rest_invalid_param', $response ); |
| 959 | $invalid = $response->data['data']['params']; |
| 960 | |
| 961 | $this->assertArrayHasKey( 'password', $invalid ); |
| 962 | $this->assertEquals( 'Passwords cannot be empty.', $invalid['password'] ); |
| 963 | } |
| 964 | |
913 | 965 | public function test_create_item_invalid_username() { |
914 | 966 | $this->allow_user_to_manage_multisite(); |
915 | 967 | wp_set_current_user( self::$user ); |
diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js
index 0df5b9e..6ba138b 100644
a
|
b
|
mockedApiResponse.Schema = { |
2531 | 2531 | } |
2532 | 2532 | }, |
2533 | 2533 | "password": { |
2534 | | "required": true, |
| 2534 | "required": false, |
2535 | 2535 | "description": "Password for the user (never included).", |
2536 | 2536 | "type": "string" |
2537 | 2537 | }, |