[wp-hackers] Get All Users with Specific capability
Dion Hulse (dd32)
wordpress at dd32.id.au
Tue Feb 15 04:15:48 UTC 2011
Why not get the list of roles which the cap it applied to then?
As you can see, other than some dodgy LIKE on wp_capabilities (Which can
contain roles AND the user might have a cap Singually outside of the
role..) or looping over all users, there isnt a way at present.
See: #10201: enhancement: Switch roles to use single role, and no
user-specific caps - http://core.trac.wordpress.org/ticket/10201
On Tue, 15 Feb 2011 12:19:46 +1100, Ryan Bilesky <rbilesky at gmail.com>
wrote:
> Im not basing it off of role though, so that won't work if the user
> customizes wp to give other roles the capability.
>
> On Mon, Feb 14, 2011 at 5:15 PM, Alex Hempton-Smith
> <hempsworth at gmail.com>wrote:
>
>> You could get the user ID's from a DB query like this:
>>
>> $wpdb->get_results("SELECT user_id FROM $wpdb->usermeta WHERE meta_key =
>> 'wp_capabilities' AND meta_value LIKE '%administrator%' ");
>>
>> That's the general idea anyway.
>>
>> Kind regards,
>> Alex Hempton-Smith
>>
>> www.alexhemptonsmith.com
>> www.twitter.com/hempsworth
>>
>>
>>
>> On Tue, Feb 15, 2011 at 1:10 AM, Ryan Bilesky <rbilesky at gmail.com>
>> wrote:
>>
>> > I need to get all users who have a specific capability, I have a
>> function
>> > with this code:
>> >
>> > global $wpdb;
>> > $members = array();
>> >
>> > // Get all user ID's
>> > $members_search = $wpdb->get_results("SELECT ID FROM $wpdb->users
>> ORDER
>> BY
>> > ID");
>> >
>> > foreach ($members_search as $userid) {
>> > // Check each user ID, check for cap
>> > if (user_can($userid, 'manage_options')) {
>> > $members[] = $userid;
>> > }
>> > }
>> >
>> > return $members;
>> >
>> > I was just wondering if there is a better way perhaps?
>> > _______________________________________________
>> > wp-hackers mailing list
>> > wp-hackers at lists.automattic.com
>> > http://lists.automattic.com/mailman/listinfo/wp-hackers
>> >
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
--
Dion Hulse / dd32
Contact:
e: contact at dd32.id.au
Web: http://dd32.id.au/
More information about the wp-hackers
mailing list