[wp-hackers] Counting the number of users who can publish posts

Jeremy Clarke jer-wphackers at simianuprising.com
Wed Jul 30 17:12:07 GMT 2008


Whenever I think it I can hear people telling me 'well why don't you
write it', but it would be great to have some standard functions to
deal with users in bulk. Really the whole user system could be a lot
clearer (get_userdata + get_currentuserinfo are pretty confusing), but
just having a get_users() function to match get_posts and get_terms
would be a great boon. (as it is my plugins need to run their own user
fetching code :S)

Right now the wp_dropdown_users() function actually does direct SQL
calls to get the users, which is pretty whack IMHO. It also doesn't
offer any capability filtering, which would be great to see in my
dream get_users() function.

Cap checking off the top of my head: if an argument for a capability
is passed, like '&has_cap=publish', it would get the list of roles
(global $wp_roles, $wp_roles->roles), iterate through them checking
for ones that have the desired _capability_, then check wp_usermeta
for people who have either the capability itself or a role that
encompases it. Not sure if that would make an incredibly slow query,
thought it seems like it might especially if you have lots of roles
and are looking for a capability they all have.

Benedict: The above should probably work and the sql wouldn't be that
crazy, you just have to do the role/cap filtering yourself in php.

-- 
Jeremy Clarke | http://simianuprising.com
Code and Design | http://globalvoicesonline.org


More information about the wp-hackers mailing list