Skip to:
Content
Pages
Categories
Search
Top
Bottom

add new roles


  • veepay
    Participant

    @veepay

    Hello,
    I would like to create new roles in bbpress.
    Since this is not easy, I have used this code

    /**
     * Neue Benutzerrollen
     */
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called Super-Administrator */
        $bbp_roles['bbp_super-administrator'] = array(
            'name' => 'Super-Administrator',
            'capabilities' => custom_capabilities( 'bbp_super-administrator' )
            );
    
        /* Add a role called Administrator */
        $bbp_roles['bbp_administrator'] = array(
            'name' => 'Administrator',
            'capabilities' => custom_capabilities( 'bbp_administrator' )
            );
    
        /* Add a role called VIP-Member */
        $bbp_roles['bbp_vip-member'] = array(
            'name' => 'VIP-Member',
            'capabilities' => custom_capabilities( 'bbp_vip-member' )
            );
    
        /* Add a role called Member */
        $bbp_roles['bbp_member'] = array(
            'name' => 'Member',
            'capabilities' => custom_capabilities( 'bbp_member' )
            );
    
        /* Add a role called Trial-Member */
        $bbp_roles['bbp_trial-member'] = array(
            'name' => 'Trial-Member',
            'capabilities' => custom_capabilities( 'bbp_trial-member' )
            );
    
        /* Add a role called User */
        $bbp_roles['bbp_user'] = array(
            'name' => 'User',
            'capabilities' => custom_capabilities( 'bbp_User' )
            );
     
        return $bbp_roles;
    }
     
    add_filter( 'bbp_get_dynamic_roles', 'add_new_roles', 1 );
     
    function add_role_caps_filter( $caps, $role )
    {
        /* Only filter for roles we are interested in! */
        if( $role == 'bbp_super-administrator' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_administrator' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_vip-member' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_member' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_trial-member' )
            $caps = custom_capabilities( $role );
    
        if( $role == 'bbp_user' )
            $caps = custom_capabilities( $role );
       
        return $caps;
    }
     
    add_filter( 'bbp_get_caps_for_role', 'add_role_caps_filter', 10, 2 );
     
    function custom_capabilities( $role )
    {
        switch ( $role )
        {
     
            /* Capabilities for 'Super-Administrator' role */
            case 'bbp_super-administrator':
                return array(
                
    				// Keymasters only
    				'keep_gate'             => true,
    
    				// Primary caps
    				'spectate'              => true,
    				'participate'           => true,
    				'moderate'              => true,
    				'throttle'              => true,
    				'view_trash'            => true,
    
    				// Forum caps
    				'publish_forums'        => true,
    				'edit_forums'           => true,
    				'edit_others_forums'    => true,
    				'delete_forums'         => true,
    				'delete_others_forums'  => true,
    				'read_private_forums'   => true,
    				'read_hidden_forums'    => true,
    
    				// Topic caps
    				'publish_topics'        => true,
    				'edit_topics'           => true,
    				'edit_others_topics'    => true,
    				'delete_topics'         => true,
    				'delete_others_topics'  => true,
    				'read_private_topics'   => true,
    
    				// Reply caps
    				'publish_replies'       => true,
    				'edit_replies'          => true,
    				'edit_others_replies'   => true,
    				'delete_replies'        => true,
    				'delete_others_replies' => true,
    				'read_private_replies'  => true,
    
    				// Topic tag caps
    				'manage_topic_tags'     => true,
    				'edit_topic_tags'       => true,
    				'delete_topic_tags'     => true,
    				'assign_topic_tags'     => true
                );
    
            /* Capabilities for 'Administrator' role */
            case 'bbp_administrator':
                return array(
                
    				// Primary caps
    				'spectate'              => true,
    				'participate'           => true,
    				'moderate'              => true,
    				'throttle'              => true,
    				'view_trash'            => true,
    
    				// Forum caps
    				'publish_forums'        => true,
    				'edit_forums'           => true,
    				'read_private_forums'   => true,
    				'read_hidden_forums'    => true,
    
    				// Topic caps
    				'publish_topics'        => true,
    				'edit_topics'           => true,
    				'edit_others_topics'    => true,
    				'delete_topics'         => true,
    				'delete_others_topics'  => true,
    				'read_private_topics'   => true,
    
    				// Reply caps
    				'publish_replies'       => true,
    				'edit_replies'          => true,
    				'edit_others_replies'   => true,
    				'delete_replies'        => true,
    				'delete_others_replies' => true,
    				'read_private_replies'  => true,
    
    				// Topic tag caps
    				'manage_topic_tags'     => true,
    				'edit_topic_tags'       => true,
    				'delete_topic_tags'     => true,
    				'assign_topic_tags'     => true,
    			);
    
            /* Capabilities for 'VIP-Member' role */
            case 'bbp_vip-member':
                return array(
                
    				// Primary caps
    				'spectate'              => true,
    				'participate'           => true,
    
    				// Forum caps
    				'read_private_forums'   => true,
    
    				// Topic caps
    				'publish_topics'        => true,
    				'edit_topics'           => true,
    
    				// Reply caps
    				'publish_replies'       => true,
    				'edit_replies'          => true,
    
    				// Topic tag caps
    				'assign_topic_tags'     => true,
    			);
    
            /* Capabilities for 'Member' role */
            case 'bbp_member':
                return array(
                
    				// Primary caps
    				'spectate'              => true,
    				'participate'           => true,
    
    				// Forum caps
    				'read_private_forums'   => true,
    
    				// Topic caps
    				'publish_topics'        => true,
    				'edit_topics'           => true,
    
    				// Reply caps
    				'publish_replies'       => true,
    				'edit_replies'          => true,
    
    				// Topic tag caps
    				'assign_topic_tags'     => true,
    			);
    
            /* Capabilities for 'Trial-Member' role */
            case 'bbp_trial-member':
                return array(
                
    				// Primary caps
    				'spectate'              => true,
    				'participate'           => true,
    
    				// Forum caps
    				'read_private_forums'   => true,
    
    				// Topic caps
    				'publish_topics'        => true,
    				'edit_topics'           => true,
    
    				// Reply caps
    				'publish_replies'       => true,
    				'edit_replies'          => true,
    
    				// Topic tag caps
    				'assign_topic_tags'     => true,
    			);
    
            /* Capabilities for 'User' role */
            case 'bbp_user':
                return array(
                
    				// Primary caps
    				'spectate'              => true,
    				'participate'           => true,
    
    				// Forum caps
    				'read_private_forums'   => true,
    
    				// Topic caps
    				'publish_topics'        => true,
    				'edit_topics'           => true,
    
    				// Reply caps
    				'publish_replies'       => true,
    				'edit_replies'          => true,
    
    				// Topic tag caps
    				'assign_topic_tags'     => true,
    			);
     
                break;
     
            default :
                return $role;
        }
    }

    Unfortunately, I have the problem that the rights are all set to deny, as soon as the user changes something in his profile.
    Can I prevent that?

    In addition I have installed the plugin “bbPress Advanced Capabilities”

    VeePay

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar