Skip to content

Commit e3d901a

Browse files
committed
#17 Include the user's login name with the display name in dropdown lists.
1 parent 9c1620a commit e3d901a

4 files changed

+44
-12
lines changed

admin/js/quick-edit-autocomplete.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ jQuery(async function ($) {
77
let searchTerm
88
const splitter = new RegExp('\\s+')
99

10+
function completeTheLabel (target, id) {
11+
const dataset = target.dataset
12+
const endpoint = `${dataset.url}/wp-json/wp/v2/users?context=edit&_fields=id,name,username&_locale=user`
13+
const search = '&include=' + id
14+
const url = endpoint + search
15+
$.ajax(
16+
{
17+
url: url,
18+
dataType: 'json',
19+
type: 'get',
20+
beforeSend: function (xhr) {
21+
xhr.setRequestHeader('X-WP-Nonce', dataset.nonce);
22+
},
23+
success: function (data) {
24+
if (data.length === 1) {
25+
item = data[0]
26+
const label = item.name + ' (' + item.username + ')'
27+
target.dataset.label = label
28+
target.dataset.p2 = label
29+
target.setAttribute('placeholder', label)
30+
31+
}
32+
}
33+
}
34+
)
35+
}
1036

1137
function setSelected(selectElement, id, label) {
1238
/* No options here? Weird. But just put one so we can use it. */
@@ -52,7 +78,7 @@ jQuery(async function ($) {
5278
let dataset
5379

5480
function fetch(req, res) {
55-
const endpoint = `${dataset.url}/wp-json/wp/v2/users?context=view&per_page=${dataset.count}&_fields=id,name&_locale=user`
81+
const endpoint = `${dataset.url}/wp-json/wp/v2/users?context=edit&per_page=${dataset.count}&_fields=id,name,username&_locale=user`
5682
const capabilities = typeof dataset.capabilities === 'string' ? '&capabilities=' + dataset.capabilities : '&who=authors'
5783
searchTerm = req.term
5884
const search = `&search=${req.term}`
@@ -69,7 +95,8 @@ jQuery(async function ($) {
6995
res(data);
7096
} else {
7197
const list = $.map(data, item => {
72-
return {label: item.name, value: item.name, id: item.id}
98+
const tag = item.name + ' (' + item.username + ')'
99+
return {label: tag, value: tag, id: item.id}
73100
})
74101
list.sort(wordMatchesFirst)
75102
res(list)
@@ -142,6 +169,7 @@ jQuery(async function ($) {
142169
target.dataset.p2 = label
143170
setSelected(selectElement, id, label)
144171
target.setAttribute('placeholder', label)
172+
completeTheLabel (target, id)
145173
}
146174
},
147175
select:

index-wp-users-for-speed.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @license GPL-2.0-or-later
88
* @wordpress-plugin0
99
* Plugin Name: Index WP Users For Speed
10-
* Version: 1.1.6
11-
* Stable tag: 1.1.6
10+
* Version: 1.1.7
11+
* Stable tag: 1.1.7
1212
* Plugin URI: https://plumislandmedia.org/index-wp-users-for-speed/
1313
* Description: Speed up your WordPress site with thousands of users.
1414
* Requires at least: 5.2
@@ -34,7 +34,7 @@
3434

3535
const INDEX_WP_USERS_FOR_SPEED_NAME = 'index-wp-users-for-speed';
3636
define( 'INDEX_WP_USERS_FOR_SPEED_FILENAME', plugin_basename( __FILE__ ) );
37-
const INDEX_WP_USERS_FOR_SPEED_VERSION = '1.1.6';
37+
const INDEX_WP_USERS_FOR_SPEED_VERSION = '1.1.7';
3838
const INDEX_WP_USERS_FOR_SPEED_PREFIX = 'index-wp-users-for-speed-';
3939
const INDEX_WP_USERS_FOR_SPEED_HOOKNAME = 'index_wp_users_for_speed_task';
4040
const INDEX_WP_USERS_FOR_SPEED_KEY_PREFIX = 'iufs';

languages/index-wp-users-for-speed.pot

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Copyright (C) 2023 Oliver Jones
1+
# Copyright (C) 2024 Oliver Jones
22
# This file is distributed under the GPL v2 or later.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: Index WP Users For Speed 1.1.5\n"
5+
"Project-Id-Version: Index WP Users For Speed 1.1.7\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/index-wp-users-for-speed\n"
77
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
88
"Language-Team: LANGUAGE <[email protected]>\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"POT-Creation-Date: 2023-02-07T08:50:36-05:00\n"
12+
"POT-Creation-Date: 2024-09-30T15:06:25+00:00\n"
1313
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14-
"X-Generator: WP-CLI 2.6.0\n"
14+
"X-Generator: WP-CLI 2.9.0\n"
1515
"X-Domain: index-wp-users-for-speed\n"
1616

1717
#. Plugin Name of the plugin
@@ -153,7 +153,7 @@ msgstr ""
153153
msgid "Approximate number of users on this entire site"
154154
msgstr ""
155155

156-
#: includes/indexer.php:172
156+
#: includes/indexer.php:175
157157
msgid "Still counting users..."
158158
msgstr ""
159159

readme.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Tags: users, database, index, performance, largesite
44
Requires at least: 5.2
55
Tested up to: 6.6
66
Requires PHP: 5.6
7-
Stable tag: 1.1.6
7+
Stable tag: 1.1.7
88
Network: true
99
License: GPL v2 or later
1010
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1111
Author URI: https://github.com/OllieJones
1212
Plugin URI: https://plumislandmedia.net/index-wp-users-for-speed/
13-
Github Plugin URI: https://github.com/OllieJones/index-wp-users-for-speed
13+
GitHub Plugin URI: https://github.com/OllieJones/index-wp-users-for-speed
1414
Primary Branch: main
1515
Text Domain: index-wp-users-for-speed
1616
Domain Path: /languages
@@ -125,6 +125,10 @@ If you configure your WordPress installation using composer, you may install thi
125125

126126
== Changelog ==
127127

128+
= 1.1.7 =
129+
130+
Display both user display name and login name in dropdowns.
131+
128132
= 1.1.6 =
129133

130134
Handles WP_User_Query operations with metadata search correctly.

0 commit comments

Comments
 (0)