• Hello,

    i am trying to put some capabilities in my plugin (MailPress).

    I developped a little role manager to allow administrator to allocate some capabilities to other roles such as editor, contributor, etc..

    My code is rather simple.
    I, first allocate all my capabilities to the administrator (code not displayed). For other roles, the capabilities are stored in a specific row in the option table (this code is activated by the ‘init’ hook.

    function roles_and_capabilities() {
    	global $wp_roles;
    	$capabilities = MP_Admin::capabilities(); // array of all plugin capabilities
    	foreach($wp_roles->role_names as $role => $name) {
    		if ('administrator' == $role) continue; // administrator already set
    
    		$r = get_role($role);
    		$rcs = get_option('MailPress_r&c_' . $role);
    		foreach ($capabilities as $capability) {
    		if (isset($rcs[$capability])) $r->add_cap($capability);
    		else	$r->remove_cap($capability);
    		}
    	}
    }

    phase 1 )i upgrade the capabilities of a role (for example, allow a menu item for ‘editor’). The menu item is not displayed because the option table is updated after the above code is executed.

    phase 2 ) The second time i activate the admin, NOTHING changes ???

    phase 3) The third time i activate the admin, the item menu allowed is displayed …

    So my question is, why in phase 2 the role/capability upgrade is ignored. Is this info cached and not updated each time ?

    Thanks for your answers

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Roles and Capabilities’ is closed to new replies.