What is the correct way to add a custom filter (a dropdown box in this case) to the admin user list (wp-admin/users.php)?
There are no filters or actions that I see to hook into that would allow me to output a select box.
I know I can inject it via javascript, but I’m hoping there’s a way to do it on the PHP side.
I am planning on using the results of that filter int as outlined here:
How to search all user meta from users.php in the admin
Actually found a potential way (with WP3.1), but it’s a bit more involved than using filters:
Since WP3.1 now uses the
WP_List_Class
to generate the admin pages, you can create your ownMy_User_List_Table
class, inheriting fromWP_Users_List_Table
and in that class override theextra_tablenav()
method. In your own method you duplicate the code fromWP_Users_List_Table::extra_tablenav()
and add your own stuff.Then you create a duplicate of
wp-admin/users.php
, modify it to use your class instead and modify the users menu entry in the admin navigation to call your duplicate instead ofwp-admin/users.php
. I’m not sure if WP3.1 now comes with easier methods to do that then the hacky solutions necessary for WP3.0.Unfortunately, all this new WP_List_Class stuff comes without good action or filter hooks, it would have been so easy had they added an
apply_filters()
call to_get_list_table()
. Grmpf.