Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbpress custom user role ?


  • buzoo
    Participant

    @buzoo

    Hi i want to extend “participant” user role so that they can delete there own replies and images they have attached(For attaching i am using a plugin called GD bbpress attachment).I got some hint from this link but being novice i got more confused were to put the code.
    Can any one tell me if there is particular plugin to do the work so that i can extend “participants” capabilities ? or help me out to configure the file according to the link as it doesn’t mention were to put them
    Thanks

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

  • Robin W
    Moderator

    @robin-w

    do you know how to add some code to your functions file – if I gave you the code?


    buzoo
    Participant

    @buzoo

    yes , i think i have to upload the filter/action function to capabilities.php in bbpress core.And one more thing i found that bbpress not looking for custom functions in /twentythirteen/bbpress/ so i have to edit the functions in main plugin.
    Thanks


    tharsheblows
    Participant

    @tharsheblows

    bbpress-functions.php should go in the main theme directory eg /twentythirteen/bbpress-functions.php. It doesn’t go in the /twentythirteen/bbpress/ directory. This is also true for the default bbpress template, bbpress.php.

    So for bbpress custom templates, you’ll have eg :

    /mytheme/bbpress-functions.php <– custom functions file, overwrites plugin file
    /mytheme/bbpress.php <– custom main bbpress index file, overwrites plugin file
    /mytheme/bbpress/*.php (eg /mytheme/bbpress/loop-forums.php) <– all the template files you want to overwrite from the plugin folder /bbpress/templates/default/bbpress/


    Robin W
    Moderator

    @robin-w

    ok,

    so create a file called bbpress-functons.php as above and in to this put

    <?php
    //code to add tutor role 
    
    function add_tutor_role( $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_tutor_role', 1 );
    
    function tutor_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', 'tutor_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'        => true,
    				'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;
    	}
    }
    
    

    This sets up a role called ‘tutor’ – just change this name everywhere to the one you want, and then edit the capabilities.

    the default capabilities for each role are :

    https://codex.bbpress.org/bbpress-user-roles-and-capabilities/

    you’ll probably want to make delete topics and delete replies true


    buzoo
    Participant

    @buzoo

    okay thanks a lot excellent support


    Robin W
    Moderator

    @robin-w

    Great, do come back if you have any further queries !


    HW
    Participant

    @hannahmwool

    Hi Robin

    Thank you for the functions code you provided to create a custom role. I’ve implemented this and can see it and change the user to the new role – however it doesn’t save it so if i navigate away from the user page and go back it hasn’t kept the role it just defaults back to nothing until i post and then it puts me on participant (which I have enabled to set automatically for new posters). Would you know why that is happening?

    My initial setup was a template file called forum.php which bbpress automatically picked up as my forum page – I didn’t use override of existing bbpress templates within my theme, however when I made the bbpress-functions.php in my theme folder it made the forum stop using the bbpress styles (not sure why) – so i tried adding the overrides for bbpress in my theme folder and that made it not render any html at all just blank body – I’ve ended up copying the stylesheet to my theme folder and naming it something else.

    I’m looking for a user role half way between a participant and a moderator (I’ve called it a Junior Moderator) where they can moderate and flag things and get in touch with users who flagged inappropriate posts and inform them of the actions as well as receive emails or notifications from users flagging the inappropriate content- but they can’t delete or edit other people’s topics, replies and can’t delete forums or add new ones.

    Any help would be appreciated!

    Thanks


    Robin W
    Moderator

    @robin-w

    hhmmmm…

    Quite a lot of info, and not sure if it is affecting

    The middle paragraph starting ‘My initial setup was a template file called…’ is worrying.

    Basically you should not be adding stuff to your main theme, instead you should use a child theme.
    Within this you will have a functions file (not a bbpress-functions file), and you would put the functions code for the custom role in the functions file.

    see

    Functions files and child themes – explained !

    The your styles should work, and the custom role should work


    HW
    Participant

    @hannahmwool

    I’m using my own custom theme so a child theme is not necessary. I got it to work by putting it into my functions.


    Robin W
    Moderator

    @robin-w

    great – glad your fixed !


    mvaneijgen
    Participant

    @mvaneijgen

    I had to create several new users but I could not just copied and paste the code again so I modified the code a bit

    
    //code to add expert role 
    
    function add_expert_role( $bbp_roles )
    {
    	/* Add a role called expert */
    	$bbp_roles['bbp_expert'] = array(
    		'name' => 'expert',
    		'capabilities' => custom_capabilities_expert( 'bbp_expert' )
    		);
    	return $bbp_roles;
    }
     
    add_filter( 'bbp_get_dynamic_roles', 'add_expert_role', 1 );
    
    function expert_role_caps_filter( $caps, $role )
    {
    	/* Only filter for roles we are interested in! */
    	if( $role == 'bbp_expert' )
    		$caps = custom_capabilities_expert( $role );
     
    	return $caps;
    }
     
    add_filter( 'bbp_get_caps_for_role', 'expert_role_caps_filter', 10, 2 );
    
    function custom_capabilities_expert( $role )
    {
    	switch ( $role )
    	{
    		 
    		/* Capabilities for 'expert' role */
    		case 'bbp_expert':
    			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'        => true,
    				'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;
    	}
    }

    This creates the role Expert. I put this in my functions.php of my child-theme


    Ahir Hemant
    Participant

    @hemant-ahir

    Hello,

    how to give link in widget forum statics: for example there is total 5 topic, i need to give link on 5 how it is possible ? plese help

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