[wp-hackers] User Capabilities
ryan at boren.nu
Fri Jul 1 15:08:17 GMT 2005
On Thu, 2005-06-30 at 23:41 -0700, Rob Lanphier wrote:
> Very cool! As far as the backwards compatibility mechanism goes, I was
> thinking it might be smart to map things the other direction as well,
> creating capabilities with names like "level1", "level2", etc, so that
> chunks of code like this:
> if ($user_level >= 6)
> ...can be replaced with this in a semi-automated fashion:
> if ($current_user_can('level6')
> ...or keeping with the natural language feel of things:
> ...and then, of course, give level 6 users the "level1" through "level6"
Yeah, we'll need stuff like this for backwards compat. One specific
instance is plugins adding new admin menus. They currently specify a
user level. They need to specify capabilities instead. To illustrate,
here's how the theme menu is currently constructed in menu.php.
$submenu['themes.php'] = array(__('Themes'), 8, 'themes.php');
$submenu['themes.php'] = array(__('Theme Editor'), 8,
In the capability model, this becomes:
$submenu['themes.php'] = array(__('Themes'), 'switch_themes',
$submenu['themes.php'] = array(__('Theme Editor'), 'edit_themes',
A capability is used instead of a user level when creating menus.
Plugins too need to be updated to create menus with capabilities instead
of user levels. However, there are a lot of plugins out there and we
need to be backwards compatible with them. So, as you suggest, user
level 10 becomes a 'level10' capability, level 5 becomes 'level5', and
so on. Roles will be assigned the 'level*' caps they need to be
compatible with old plugins.
More information about the wp-hackers