Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: bbpress custom user role ?

@robin-w

Moderator

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

Skip to toolbar