[wp-hackers] Making Capability Manager site wide for MU

Jordi Canals jordi at jcanals.cat
Sat Nov 28 22:40:12 UTC 2009

Hello all,

I have a plugin called 'Capability Manager' wich works fine from now. (You
can find it at http://wordpress.org/extend/plugins/capsman/)
Some users and myself, suggested to introduce an special feature for
WordPress MU.

The plugin just manages role capabilities (Not user capabilities), and it's
a very simple one. For WordPress MU it works well if you want to manage
capabilities at blog level. But what I want to introduce now, is to manage
them at site level. I mean, when setting/unsetting a capability in the site,
It will set/unset it on any blog in this site, overwriting individual blog
roles and capabilities. The problem is that it looks that there is no Site
Level Roles and Capabilities, so I'm doing it.

The first thing is to determine if I'm running on MU which I think I can do
by checking if the constant VHOST is defined. Don't know if there is a
better way to do it.

About overwriting roles to use them site wide, my approach is the following
(And some draft code):

I will use the following filters:


Just this two as we are never going to delete the role options. And want to
maintain a copy of the roles on the managed blog.

The code would look something like that:

$my_roles = $wpdb->prefix . 'user_roles';

add_filter('pre_option_' . $my_roles, 'my_get_role_option');
add_action('update_option_' . $my_roles, 'my_update_role_option', 2);

function my_get_role_option ( $default ) {
    global $wpdb;
    return get_site_option($db->base_prefix . 'user_roles', $default);

function my_update_role_option($oldvalue, $newvalue) {
    global $wpdb;
    update_site_option($wpdb->base_prefix . 'user_roles', $newvalue);

This is just an approach draft, not tested yet. All other functionallity
managing cpabilities, creating and deleting roles is done (for blogs).
I think with just this two filter/action, It should run, as I get and save
the options to the sitemeta table, does not mind what blog I'm on.
Only global site admins will have access to manage capabilities.

Any comment or suggestion about this will be really welcome. Look just at
the idea, not the code itself (as the code can contain coding errors).

Thanks in advance,

Jordi Canals

More information about the wp-hackers mailing list