• Hello,

    I am using the WordPress user and role management system. I’ve found that if user has multiple roles and one of the roles doesn’t have any capabilities (like the Subscriber role) then when get_role_caps gets called the array_merge will kill the array because the role->capabilites in not an Array but is null.

    function get_role_caps() {
                    global $wp_roles;
    
                    if ( ! isset($wp_roles) )
                            $wp_roles = new WP_Roles();
    
                    //Filter out caps that are not role names and assign to $this->roles
                    if(is_array($this->caps))
                            $this->roles = array_filter(array_keys($this->caps), array(&$wp_roles, 'is_role'$
    
                    //Build $allcaps from role caps, overlay user's $caps
                    $this->allcaps = array();
                    foreach( (array) $this->roles as $role) {
                            $role = $wp_roles->get_role($role);
    //This function (array_merge) is merging allcaps with
    // a null in the role capabilities (meaning no capabilities like the Subscriber role) which returns a null and all the person's capabilities get thrashed.
                            $this->allcaps = array_merge($this->allcaps, $role->capabilities);
                    }
                    $this->allcaps = array_merge($this->allcaps, $this->caps);
            }

    the hack is to create a capability that does nothing and add it to all the roles so that there is at least one capability in each role, thus causing this merge to always have something to merge. A better fix would be for you guys to actually check if the role capabilities is an array before merging it

    Also, while your at this, can you please fix this one too?
    http://wordpress.org/support/topic/131509?replies=1

  • The topic ‘allcaps in WP_User is not collecting caps from roles correctly’ is closed to new replies.