[wp-hackers] Get All Users with Specific capability

Ryan Bilesky rbilesky at gmail.com
Wed Feb 16 01:07:27 UTC 2011

Better yet, I am not going to map to WP capabilities, I can have the user
choose what wp users they want to do this in the options page and store that
directly in an array, simplest and cleanest way to get the job done as far
as i can tell.

On Tue, Feb 15, 2011 at 4:55 PM, Ryan Bilesky <rbilesky at gmail.com> wrote:

> I was also thinking I might need to have a hook that will fire when roles
> and capabilities are changed, is there such a hook in the roles class that
> gets fired?
> On Tue, Feb 15, 2011 at 4:48 PM, Jeremy Clarke <jer at simianuprising.com>wrote:
>> In 3.1 you can use get_users('role=subscriber') to avoid using any custom
>> SQL but like you say that is not usually good enough and capabilities are
>> fundamentally more useful and important in WP (especially in public
>> plugins
>> where you can't make any assumptions about roles).
>> IMHO get_users() should be able to take in a capability as well as roles,
>> too bad that wasn't included in 3.1. It's certainly a complicated problem,
>> but it doesn't seem impossible, just potentially irresponsible WRT server
>> performance (you'd want to cache it if you use it on most pageloads).
>> On Tue, Feb 15, 2011 at 6:59 PM, Ryan Bilesky <rbilesky at gmail.com> wrote:
>> > Ok so basically there isn't a better way.  Now I can make this easier by
>> > caching the resulting array in say a site option, then most the time all
>> I
>> > have to do is pull a site option.  Then I just need to find the
>> necessary
>> > hooks pto update the data when it has or may have changed.  So I need to
>> > find hooks for when role/capabilities are changed and a hook when a user
>> > changes roles.  Does anyone know of any such hooks, am I missing any
>> otherd
>> > id need?
>> >
>> >
>> Here's the actions I attach my own user caching system to:
>> function gv_hook_user_udpate($user_id, $old_user_data = '') {
>>     gv_update_cached_user($user_id);
>> }
>> add_action('profile_update', 'gv_hook_user_udpate', '', 2);
>> add_action('user_register', 'gv_hook_user_udpate', '', 1);
>> That seems to cover most scenarios, though there could easily be edge
>> cases
>> that aren't covered, especially because often cap/role related changes are
>> made using plugins that probably don't call profile_update after changing
>> a
>> user. Having this data reload at regular intervals is going to be
>> important.
>> I'd recommend using the Transients API instead of options, as it will
>> handle
>> expiration for you: https://codex.wordpress.org/Transients_API
>> --
>> Jeremy Clarke • jeremyclarke.org
>> Code and Design • globalvoicesonline.org
>>  _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list