[wp-trac] Re: [WordPress Trac] #5541: Refactor and simplify WP_Roles

WordPress Trac wp-trac at lists.automattic.com
Sun Dec 30 11:19:03 GMT 2007

#5541: Refactor and simplify WP_Roles
 Reporter:  tellyworth   |        Owner:  anonymous
     Type:  enhancement  |       Status:  new      
 Priority:  normal       |    Milestone:  2.5      
Component:  General      |      Version:           
 Severity:  normal       |   Resolution:           
 Keywords:  has-patch    |  
Comment (by tellyworth):

 It'd be easy enough for a plugin to fetch the old db roles and load them
 by hooking the init_roles action.  Off the top of my head, something like:

 function load_db_roles(&$_roles) {
    $role_key = $wpdb->prefix . 'user_roles';
    $roles = get_option($role_key);
    foreach ($roles as $k=>$role) {
       $_roles->add_role($k, $role['name'], $role['capabilities']);
 add_action('init_roles', 'load_db_roles');

 My initial thought on upgrades was, we could examine the old db roles at
 upgrade time, use array_diff() to find any differences from the default
 roles, and then store just the diffs in the db (or nothing, if there are
 no diffs).  Then at runtime we load the db roles (if any) and merge it
 into the new hard-coded roles.  That'd be seamless if it worked, but is
 probably overkill and a bit too fragile.

Ticket URL: <http://trac.wordpress.org/ticket/5541#comment:2>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list