[wp-hackers] Get All Users with Specific capability

Ryan Bilesky rbilesky at gmail.com
Tue Feb 15 01:19:46 UTC 2011


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
>


More information about the wp-hackers mailing list