I thought I’d share some simple JavaScript to hide specific users from the Users
list. I imagine this could be way more graceful if done via a plugin, but I am not brave enough to do that yet! Also, this needs to be done for each theme and this is hard-coded to work with the Light
theme only! Principles apply to any theme.
Let’s say you have users called james-admin
and another-admin
and you do not want them to be openly visible to all users. Simply add the following custom script to the </body>
customisation (Settings -> Customize -> Themes -> Light -> </body>
):
<script type="text/javascript">
// hidden users
let hidden_users = [ "james-admin", "another-admin" ];
// when a page is loaded via AJAX
$( document ).ajaxComplete( function( event, xhr, settings ) {
// check if on the user list
if ( settings.url.startsWith("/directory_items?") ) {
// find all containers with hidden users
hidden_users.forEach(function ( hidden_user ) {
$( "a:contains('" + hidden_user + "')" ).each( function() {
// double-check
if ( this.text === hidden_user ) {
// mask / hide the user (specific to this theme!)
$( this ).closest( "tr" ).remove();
}
});
});
}
});
</script>
Comments welcome!