Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FrankM1/5546338 to your computer and use it in GitHub Desktop.
Save FrankM1/5546338 to your computer and use it in GitHub Desktop.
/**
* Go to the user list in WordPress, like at
* /wp-admin/network/users.php?orderby=login&order=asc
* Ensure the screen options are set to show all users on the same page.
* Then paste the following into your browser's JavaScript console.
* The list of users will then be output to the clipboard or in an alert.
* This is known to work in Chrome.
*/
(function () {
var current_user_id = prompt("What is your user's ID?", '1'); // @todo Better to automatically determine this
var csv = '';
var rows = document.querySelectorAll('#the-list tr');
var cols = [
'ID',
'username',
'display_name',
'email'
];
csv += cols.join(', ') + "\n";
Array.prototype.forEach.call(rows, function (row) {
var user_link = row.querySelector('.column-username strong > a');
var id;
if (user_link.href.indexOf('profile.php') !== -1) {
id = current_user_id;
}
else {
id = user_link.href.match(/user_id=(\d+)/)[1];
}
var username = user_link.textContent;
var name = row.querySelector('.column-name').textContent;
var email = row.querySelector('.column-email').textContent;
cols = [
id,
username,
'"' + name + '"',
email
];
csv += cols.join(', ') + "\n";
});
if (typeof copy !== 'undefined') {
copy(csv);
}
else {
alert(csv);
}
return csv;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment