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
7 changes: 6 additions & 1 deletion src/wp-admin/includes/class-wp-users-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = "<a class='resetpassword' href='" . wp_nonce_url( "users.php?action=resetpassword&amp;users=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Send password reset' ) . '</a>';
$reset_url = add_query_arg(
'wp_http_referer',
wp_unslash( $_SERVER['REQUEST_URI'] ),
"users.php?action=resetpassword&users=$user_object->ID"
);
$actions['resetpassword'] = "<a class='resetpassword' href='" . wp_nonce_url( $reset_url, 'bulk-users' ) . "'>" . __( 'Send password reset' ) . '</a>';
}

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/tests/admin/wpUsersListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,31 @@ public function test_single_row_escapes_user_login() {
$this->assertMatchesRegularExpression( '#<strong>(<a [^>]+>)?&lt;svg onload=alert\(1\)&gt;#', $row, 'The escaped login should be shown in the username column.' );
$this->assertStringContainsString( 'Select &lt;svg onload=alert(1)&gt;', $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' ) ) );
if ( is_multisite() ) {
grant_super_admin( get_current_user_id() );
}

$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 );
}
}
Loading