Skip to:
Content
Pages
Categories
Search
Top
Bottom

Prevent participants from creating new topics


  • jessicana
    Participant

    @jessicana

    Hello

    I want to prevent user role with participant from creating new topics. By default, registered users are given the participant role. I want the forums to be organized and if I allow everyone in they will mess the forums.

    I read this: https://bbpress.org/forums/topic/prevent-users-from-creating-topics/

    But it’s no longer applicable to the current version.

    I tried this fix:

    .bbp-topic-form {
    	display: none;
    }

    But it’s incorrect because users will not be able to edit their replies and it affects the functionality of forums.

    Please help!

Viewing 3 replies - 1 through 3 (of 3 total)

  • Robin W
    Moderator

    @robin-w

    The best way would be to create a new role, and not give it the create topic capability

    see

    https://codex.bbpress.org/custom-capabilities/

    and give it :

    // Topic caps
    ‘publish_topics’ => false,
    ‘edit_topics’ => false,
    ‘edit_others_topics’ => false,
    ‘delete_topics’ => false,
    ‘delete_others_topics’ => false,
    ‘read_private_topics’ => true,

    Hi,
    If you want to use the same permissions/capabilities on all your forums, then a new custom role with the above capabilities is the best way to go.
    If you want to ‘protect’ only some of your (sub)forums against new topic creation, then you can use my bbP Toolkit plugin (https://wordpress.org/plugins/bbp-toolkit/).
    Pascal.


    jessicana
    Participant

    @jessicana

    Hello

    Thanks. Just to confirm with you, suppose the role tutor is a role that can not create topics but can edit the reply s/he creates. Accordingly, is the code below be correct?

    
    //code to add tutor role 
     
    function add_new_roles( $bbp_roles )
    {
        /* Add a role called tutor */
        $bbp_roles['bbp_tutor'] = array(
            'name' => 'Tutor',
            'capabilities' => custom_capabilities( 'bbp_tutor' )
            );
     
        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_tutor' )
            $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 'tutor' role */
            case 'bbp_tutor':
                return array(
                    // Primary caps
                    'spectate'              => true,
                    'participate'           => true,
                    'moderate'              => false,
                    'throttle'              => false,
                    'view_trash'            => false,
     
                    // Forum caps
                    'publish_forums'        => false,
                    'edit_forums'           => false,
                    'edit_others_forums'    => false,
                    'delete_forums'         => false,
                    'delete_others_forums'  => false,
                    'read_private_forums'   => true,
                    'read_hidden_forums'    => false,
     
                    // Topic caps
                    'publish_topics'        => false,
                    'edit_topics'           => true,
                    'edit_others_topics'    => false,
                    'delete_topics'         => false,
                    'delete_others_topics'  => false,
                    'read_private_topics'   => true,
     
                    // Reply caps
                    'publish_replies'       => true,
                    'edit_replies'          => true,
                    'edit_others_replies'   => false,
                    'delete_replies'        => false,
                    'delete_others_replies' => false,
                    'read_private_replies'  => true,
     
                    // Topic tag caps
                    'manage_topic_tags'     => false,
                    'edit_topic_tags'       => false,
                    'delete_topic_tags'     => false,
                    'assign_topic_tags'     => true,
                );
     
                break;
     
            default :
                return $role;
        }
    }

    Thanks

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