[wp-trac] [WordPress Trac] #17924: Make Integrating Multiple Roles Per User Easier for Plugin Authors
WordPress Trac
noreply at wordpress.org
Thu Dec 5 16:17:14 UTC 2013
#17924: Make Integrating Multiple Roles Per User Easier for Plugin Authors
-----------------------------+-----------------------------
Reporter: mobius5150 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Role/Capability | Version: 3.2
Severity: normal | Resolution:
Keywords: has-patch |
-----------------------------+-----------------------------
Changes (by nikolov.tmw):
* cc: ico.the.star.dust@… (added)
Comment:
For anyone interested in using that on their sites, I wrote a little
plugin that will allow you to set multiple roles per user. Of course in a
standard WordPress environment, there isn't much use of that, since the
user will have the privileges of the most-powerful role(since every role
that has more privileges builds on top of the privileges of the previous
one).
But since you need that kind of plugin, I assume you are using custom
privileges and roles.
You can take a look at the code here - https://gist.github.com/nikolov-
tmw/7808046 or you can download a bundled .zip file of the plugin here -
http://paiyakdev.com/downloads/multiple-roles-per-user.zip
I've tested the plugin on a pretty basic install with very little plugins
and on an install with multiple plugins.
What this plugin doesn't do for you is to give you an easy way to
programmatically set multiple roles per user. But, since that's already
built-in to the WP_User class, you can do it in the same way the plugin
does it:
{{{
$user = new WP_User( $user_id );
$user->add_role( 'role1' );
$user->add_role( 'role2' );
}}}
It's rather simple in my opinion and I don't see why you'd need to be able
to specify an array of roles when you use `wp_insert_user()`.
Just make sure to either specify an empty string, or at least one of the
roles for a user when you do `wp_insert_user()` - otherwise your new user
would have the default role(which might not be the desired result in some
cases).
--
Ticket URL: <http://core.trac.wordpress.org/ticket/17924#comment:41>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list