[wp-hackers] Capabilities and Plugins

Sam Angove sam at rephrase.net
Sun Mar 5 08:17:43 GMT 2006


On 3/5/06, Mark Jaquith <mark.wordpress at txfx.net> wrote:
> As it is now, there is no way for a third party role manager plugin
> (like Owen's... is there another one?) to know about the capabilities
> that a plugin uses unless that plugin adds the capability to an
> existing role.

Just curious, but why aren't plugins granting caps to the
administrator role as a matter of course? They'll be able to grant it
to themselves anyway, after all, and it seems like a good
policy/best-practice.

(And there's always $grant = false, so adding a cap to the role
doesn't have to mean granting it. )

>
> An easy way to add the plugin's capability to all roles with
> manage_options capability [...]

That'd be pretty cool as a generic function -- let a plugin give all
roles with `manage_comments` the `ajax_delete_comment` cap, say. I'd
use it, though for the time being I'm satisfied with something like

	foreach ( array_keys($wp_roles->get_names()) as $role_name ) {
		$role =& get_role($role_name);
		if ( $role->has_cap('manage_options') ) {
			$role->add_cap('some_plugin_cap');
		}	
	}


More information about the wp-hackers mailing list