From 52edebad9eb99409b3b63315f6696fa310d2bb52 Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Mon, 16 Nov 2026 14:42:32 +0530 Subject: [PATCH 1/2] Users: Preserve the list after sending password reset --- .../includes/class-wp-users-list-table.php | 7 +++++- .../phpunit/tests/admin/wpUsersListTable.php | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-users-list-table.php b/src/wp-admin/includes/class-wp-users-list-table.php index 46eac2064660e..0cd2bfa67f072 100644 --- a/src/wp-admin/includes/class-wp-users-list-table.php +++ b/src/wp-admin/includes/class-wp-users-list-table.php @@ -504,7 +504,12 @@ public function single_row( $user_object, $style = '', $role = '', $numposts = 0 && current_user_can( 'edit_user', $user_object->ID ) && true === wp_is_password_reset_allowed_for_user( $user_object ) ) { - $actions['resetpassword'] = "" . __( 'Send password reset' ) . ''; + $reset_url = add_query_arg( + 'wp_http_referer', + wp_unslash( $_SERVER['REQUEST_URI'] ), + "users.php?action=resetpassword&users=$user_object->ID" + ); + $actions['resetpassword'] = "" . __( 'Send password reset' ) . ''; } /** diff --git a/tests/phpunit/tests/admin/wpUsersListTable.php b/tests/phpunit/tests/admin/wpUsersListTable.php index b1ebab4ca6b14..652ed1328106c 100644 --- a/tests/phpunit/tests/admin/wpUsersListTable.php +++ b/tests/phpunit/tests/admin/wpUsersListTable.php @@ -51,4 +51,28 @@ public function test_single_row_escapes_user_login() { $this->assertMatchesRegularExpression( '#(]+>)?<svg onload=alert\(1\)>#', $row, 'The escaped login should be shown in the username column.' ); $this->assertStringContainsString( 'Select <svg onload=alert(1)>', $row, 'The escaped login should be in the checkbox label.' ); } + + /** + * The reset password action preserves the current users list URL. + * + * @ticket 57508 + * + * @covers WP_Users_List_Table::single_row + */ + public function test_single_row_reset_password_action_preserves_list_table_query() { + wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); + + $user = get_userdata( self::factory()->user->create( array( 'role' => 'subscriber' ) ) ); + + $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : null; + $_SERVER['REQUEST_URI'] = '/wp-admin/users.php?s=example&paged=50'; + $row = $this->table->single_row( $user ); + if ( null === $request_uri ) { + unset( $_SERVER['REQUEST_URI'] ); + } else { + $_SERVER['REQUEST_URI'] = $request_uri; + } + + $this->assertStringContainsString( 'wp_http_referer=%2Fwp-admin%2Fusers.php%3Fs%3Dexample%26paged%3D50', $row ); + } } From 8ef02da26b74383d14973818c439f8cb80779fe1 Mon Sep 17 00:00:00 2001 From: ArkaPrabhaChowdhury Date: Mon, 16 Nov 2026 15:06:26 +0530 Subject: [PATCH 2/2] Tests: Grant super admin for password reset link --- tests/phpunit/tests/admin/wpUsersListTable.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/phpunit/tests/admin/wpUsersListTable.php b/tests/phpunit/tests/admin/wpUsersListTable.php index 652ed1328106c..26d018a713220 100644 --- a/tests/phpunit/tests/admin/wpUsersListTable.php +++ b/tests/phpunit/tests/admin/wpUsersListTable.php @@ -61,6 +61,9 @@ public function test_single_row_escapes_user_login() { */ public function test_single_row_reset_password_action_preserves_list_table_query() { wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); + if ( is_multisite() ) { + grant_super_admin( get_current_user_id() ); + } $user = get_userdata( self::factory()->user->create( array( 'role' => 'subscriber' ) ) );