[wp-hackers] Get list of roles
Ryan Bilesky
rbilesky at gmail.com
Sat Sep 11 20:56:28 UTC 2010
thats interesting. I was just going to do this to keep administrator out of
the loop, since no matter what admins should have all of my custom
capabilities.
global $wp_roles;
$roles = $wp_roles->get_names();
foreach ($roles as $role_name=>$display_name) {
if ($role_name != 'administrator') {
// Show cap settings for role
}
}
On Sat, Sep 11, 2010 at 12:30 PM, Jeremy Clarke <jer at simianuprising.com>wrote:
> The ideal function is get_editable_roles() from /wp-admin/includes/user.php
>
> function get_editable_roles() {
> global $wp_roles;
>
> $all_roles = $wp_roles->roles;
> $editable_roles = apply_filters('editable_roles', $all_roles);
>
> return $editable_roles;
> }
>
> It's basically the same as above but its API and thus better. It will offer
> plugins a chance to filter the list in case someone other than admin has
> 'edit_users' privilege (and thus 'admin' needs to be removed from the list,
> else that user could make themselves admin).
>
> Presumably your plugin will only offer the settings page in question to
> someone who has admin-level capabilities like 'manage_options' and is
> basically an admin with access to all roles, so the filter shouldn't affect
> you.
>
> There is also wp_dropdown_roles() which gives you the roles as <option>
> fields for a <select> (though checkboxes are likely to work better in many
> scenarios where you're choosing who has access to something).
>
> --
> Jeremy Clarke | http://jeremyclarke.org
> Code and Design | http://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