Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/wp-admin/includes/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function edit_user( $user_id = 0 ) {
$update = false;
}

if ( ! $update && isset( $_POST['user_login'] ) ) {
$user->user_login = sanitize_user( wp_unslash( $_POST['user_login'] ), true );
if ( ! $update ) {
$user->user_login = isset( $_POST['user_login'] ) ? sanitize_user( wp_unslash( $_POST['user_login'] ), true ) : '';
}

$errors = new WP_Error();
Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/tests/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,28 @@ public function action_check_passwords_blank_password( $user_login, &$pass1 ) {
$pass1 = '';
}

/**
* Checks that calling edit_user() without a username when adding returns the username error.
*
* @ticket 36303
*
* @covers ::edit_user
*/
public function test_edit_user_missing_user_login() {
$_POST = array();
$_GET = array();
$_REQUEST = array();
$_POST['role'] = 'subscriber';
$_POST['email'] = 'user1@example.com';
$_POST['pass1'] = 'password';
$_POST['pass2'] = 'password';

$response = edit_user();

$this->assertWPError( $response );
$this->assertContains( 'user_login', $response->get_error_codes() );
}

/**
* @ticket 16470
*/
Expand Down
Loading