[wp-trac] Re: [WordPress Trac] #2531: Functions for registering
additional capabilities and getting a list of all capabilities
WordPress Trac
wp-trac at lists.automattic.com
Mon Mar 6 06:47:54 GMT 2006
#2531: Functions for registering additional capabilities and getting a list of all
capabilities
----------------------------+-----------------------------------------------
Id: 2531 | Status: new
Component: Administration | Modified: Mon Mar 6 06:47:54 2006
Severity: normal | Milestone: 2.1
Priority: normal | Version: 2.0.1
Owner: anonymous | Reporter: markjaquith
----------------------------+-----------------------------------------------
Changes (by markjaquith):
* keywords: => has-patch 2nd-opinion
Comment:
Ok, here's how it works:
{{{
register_cap('my_awesome_cap');
}}}
This adds (if not already there) 'my_awesome_cap' to an array option
called 'caplist' in the options table. This is the same option that
Owen's Role Manager plugin uses, so capabilities registered with
register_cap '''automatically show up in the Role Manager'''
{{{
unregister_cap('my_awesome_cap');
}}}
This removes (if it exists) 'my_awesome_cap' from the 'caplist' option
array. This could be done on deactivation of the plugin. Note that this
does not remove the capability from any users who may still have it... if
you reactivated the plugin, the capabilities would still be there. It is
just a way of purging the capability altogether if no one is using it.
{{{
get_all_caps();
}}}
This returns a unique array of all available caps. This array is merged
from three other arrays:
1) the list of caps stored in 'caplist'
2) the capabilities that are actually assigned to roles or users
3) the default capabilities that WordPress offers
number 3 was needed so that if you remove a built-in capability from all
roles an users, it doesn't disappear forever.
Here is a test plugin. You can use this plus Owen's Role Manager to test.
1) Activate Role Manager
2) Activate "My Awesome Cap" plugin
3) View Role Manager, and verify that "My Awesome Cap" exists
4) Deactivate "My Awesome Cap" plugin
5) View Role Manager, and verify that "My Awesome Cap" is gone.
6) Reactivate "My Awesome Cap" plugin
7) Assign "My Awesome Cap" to a role in the Role Manager
8) Deactivate "My Awesome Cap" plugin
9) View Role Manager and verify that "My Awesome Cap" has remained,
because it is assigned to a role.
{{{
<?php
/*
Plugin Name: My Awesome Cap
*/
register_activation_hook(__FILE__, create_function('$a=0',
'register_cap(\'my_awesome_cap\');'));
register_deactivation_hook(__FILE__, create_function('$a=0',
'unregister_cap(\'my_awesome_cap\');'));
?>
}}}
--
Ticket URL: <http://trac.wordpress.org/ticket/2531>
WordPress Trac <http://wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list