Skip to:
Content
Pages
Categories
Search
Top
Bottom

limited capabilities for roles in a specific forum


  • redwolf83
    Participant

    @redwolf83

    Hello all,

    Thanks in advance for all your coding guys.

    As writeen in the topic, I would like to be able to have a forum where only moderators can create new topics, and other users can only reply to these.

    there’s a plugin over there to make this? or I can modify functions.php of my child-theme to have this that works?

    Thanks for your Attention and for your work guys.

    Have a Nice day!

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

  • Robin W
    Moderator

    @robin-w


    redwolf83
    Participant

    @redwolf83

    Thanks, that is very helpful, but it change roles globally. I need it for a specific forum.

    • is possible call these actions to an existing role?
    • and is possible call them only for a specific forum

    I tried this but seems not work…. :/

    // BBPRESS ROLES CONFIG FOR SPECIFIC FORUM
    
    if ( bbp_forum_title(); == "My Forum Title" ) {
    
    	function add_role_caps_filter( $caps, $role )
    	{
        	/* Only filter for roles we are interested in! */
        	if( $role == 'participant' )
            	$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 'participant':
               	 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'   => false,
                    	'read_hidden_forums'    => false,
     
                    	// Topic caps
                    	'publish_topics'        => false,
                    	'edit_topics'           => false,
                    	'edit_others_topics'    => false,
                    	'delete_topics'         => false,
                    	'delete_others_topics'  => false,
                    	'read_private_topics'   => false,
     
    	                // Reply caps
    	                'publish_replies'       => true,
                    	'edit_replies'          => true,
                    	'edit_others_replies'   => false,
                    	'delete_replies'        => true,
                    	'delete_others_replies' => false,
                    	'read_private_replies'  => false,
     
                    	// Topic tag caps
                    	'manage_topic_tags'     => false,
                    	'edit_topic_tags'       => false,
                    	'delete_topic_tags'     => false,
                    	'assign_topic_tags'     => false,
               	 );
     
                	break;
     
            	default :
               	return $role;
        		}
    	}
    }

    Robin W
    Moderator

    @robin-w

    sorry capabilities are forum wide, and lots of code would be needed to make them forum specific.

    I can’t immediately think of an alternate solution


    redwolf83
    Participant

    @redwolf83

    Ok, Thanks. I have already thought an alternate solution. If forum == “forum” → If user_role == participant → sweep away the topic composer from the forum. I’ve hide the dashboard and admin bar for participant, so this could be a solution I think. May you help me to make something like this?


    Robin W
    Moderator

    @robin-w

    yes you would just put that code in form-topic.php

    wp-content/plugins/bbpress/templates/default/bbpress/form-topic.php

    create a directory on your theme called ‘bbpress’
    ie wp-content/themes/%your-theme-name%/bbpress

    where %your-theme-name% is the name of your theme

    find
    wp-content/plugins/bbpress/templates/default/bbpress/form-topic.php

    Make a copy of this file, and put in in the directory called bbpress that you created above, so you end up with
    wp-content/themes/%your-theme-name%/bbpress/form-topic.php

    bbPress will now use this template instead of the original

    you can then look at how the form does this, and put the appropriate lines in.


    redwolf83
    Participant

    @redwolf83

    Ok, Thanks Robin, I’ve solved the matter.

    at the beginning of form-topic.php I’ve added this code

    <?php 
    $forumid = bbp_get_forum_id();
    if ($forumid == YourForumID(in numbers without quote.)  ) {
    	$displayed_user = bbp_get_user_id( 0, false, true ); 
    	$role = bbp_get_user_role($displayed_user);
    	if ( $role == "bbp_participant" ) {
                   echo '<div class="bbp-template-notice">This forum is marked as closed to new topics from participant, however your can reply to existing topics</div>';
                   return; } 
    }
     ?>

    Thanks for your help, 🙂 ::cheers::
    Have a Nice day!


    Robin W
    Moderator

    @robin-w

    great – glad you’re fixed !

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