The first code section in this recipe is a filter function that gets a list of all columns that the system intends on displaying in the users section of the administration interface. While we could have just added our new entry at the end of the array, similar to what we did in the Displaying additional columns in the custom post list page recipe in Chapter 4, The Power of Custom Post Types, we take a more advanced approach in this recipe; we use the PHP array_slice function to split the columns array into two sections and insert our new column name between the existing items.
We continue this recipe by providing a function that displays the user level assigned to each user. This is done by simply retrieving the information based on the current user ID and returning the data to be displayed. It should be noted that the user management page takes an approach that is slightly different from the post and pages custom column content, since it uses a filter function where we return data instead of using an action hook that directly sends content to the browser.
The next code section is responsible for rendering a drop-down list of user levels that can be used to filter the user list; this is done by using standard HTML and code to loop through the list of user levels and display them. Unfortunately, WordPress complicates things by calling our function twice, before and after listing users, resulting in two drop-down lists on the same page with no way to differentiate them. To avoid having issues with the two drop-down lists being set to different values and sending these conflicting values to our filtering code, the next function places Javascript code in the page footer of all the user listing pages. This allows us to synchronize either drop-down list with the other's value when the user interacts with them.
Our last step consists of modifying the user query if we find a filtering argument in the page URL when displaying the user listing. If an argument is found and the page is the correct one, we will check whether the value is part of our user levels array and then add it to the system's current query variables.