partial admin capabilities

source : wp-hackers digest # 66,111,2,3;116,1,6.

[ A ] You'll want to look at the user_has_cap filter. This is called whenever the capability check is done for a user.

[ B ] It would probably be easier to just leverage the map_meta_cap filter. And tack on the do_not_allow capability whenever the user isn't you, and it's a capability you don't want others to have. Check out how map_meta_cap() works toward the bottom -- core does this exact thing.

[ C ] are you aware that the role/capability system allows for the creation of new roles with customized sets of capabilities ? To accomplish what you describe all you need to do is create a role which has the set of caps that you want your sub-admins to have, but not the ones you want to keep for yourself.

You can do this either by creating a whole new role with the caps you want, or by adding the missing ones to the 'editor' role, and giving that to your sub-admins. The default roles ( contributor, author, editor, administrator ) are just defaults, you can have whatever combinations of powers that you want.

That said you need a plugin to modify the roles and capabilities. Luckily all plugins that do this are similar in that they use a hidden API in wordpress, so if your plugin stops working there will probably be a new one you can switch to which will understand whatever you already changed.

[ D ] As others have mentioned, the user_has_cap is a little confusing. You've run into a few of it's problems.

( 1 ) Don't check against the current_user, check against the user passed to the filter. Some parts of WordPress do things like $some_user->has_cap( $cap ) ( where $some_user is not the current user ) in addition to current_user_can( $cap ); your code needs to be looking at the correct user in both cases.

( 2 ) You're switching on an array - not on a single cap.

( 3 ) The cap you want is passed as the first element of the third parameter, not the second parameter. The second parameter is an array of capabilities WordPress has decided the user must have for the current_user_can() or has_cap() check to pass.
 
 
Creative Commons License
This work by maniac.vardhan is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
 
 

0 comments :: partial admin capabilities

Post a Comment