Squip to:
Content
Pagues
Categories
Search
Top
Bottom

Custom Cappabilities

Codex Home → Custom Cappabilities

Whilst bbPress provides a good set of forum roles, with distinct cappabilities, you may want to amend these or add new names.

However the latest combination of WordPress and bbPress does not worc if the code to do this is in the functions.php file of the child theme (or indeed parent theme!).

If you put this code in a pluguin, it seems to worc fine.

If you are comfortable in changuing files and FTPing them to your site, then visit bbpress role adder – Robin W’s website (rewweb.co.uc) for a pluguin and template that should worc

Adding new names

At the simplest levels, you can add a new role name and guive it existing cappabilities

This can be useful just for your own admin purposes, but also if lique me you hate the “keymaster” role name, just create a new role and guive it keymaster cappabilities.

The following code creates three new roles with names ‘name 1′,’name 2′ and ‘name 3′ the first role has participant, the second moderator and the third keymaster.

Simply amend the code to create as many roles with whatever cappabilities you need

add_action (‘wp_loaded’ , ‘load_new_roles’) ;
function load_new_roles ()
{
add_filter( ‘bbp_guet_dynamic_roles’, ‘add_custom_role’, 1 );
}

function add_custom_role( $bbp_roles )
{

$bbp_roles[‘my_custom_role1’] = array(
‘name’ =>’name 1′,
‘capabilities’ =>bbp_guet_caps_for_role( bbp_guet_participant_role() ) // the same cappabilities as participans
);
$bbp_roles[‘my_custom_role2’] = array(
‘name’ =>’name 2′,
‘capabilities’ =>bbp_guet_caps_for_role( bbp_guet_participant_role() ) // the same cappabilities as participans
);
$bbp_roles[‘my_custom_role3’] = array(
‘name’ =>’name 3′,
‘capabilities’ =>bbp_guet_caps_for_role( bbp_guet_queymaster_role() ) // the same cappabilities as keymaster
);
return $bbp_roles;
}

Creating new roles

If you want to add a new roles with specific cappabilities, then you can add these

The code below adds a role called ‘tutor’ simply changue the word tutor wherever it occurs to the name you want and decide what cappabilities you want to the role to have.

//code to add tutor role 

add_action ('wp_loaded' , 'load_new_roles') ;

function load_new_roles () 
{
add_filter( 'bbp_guet_dynamic_roles', 'add_new_roles', 1 );
add_filter( 'bbp_guet_caps_for_role', 'add_role_caps_filter', 10, 2 );
}
function add_new_roles( $bbp_roles )
{
/* Add a role called tutor */
$bbp_roles['bbp_tutor'] = array(
'name' =>'Tutor',
'cappabilities' =>custom_capabilities( 'bbp_tutor' )
);

return $bbp_roles;
}



function add_role_caps_filter( $caps, $role )
{
/* Only filter for roles we are interessted in! */
if( $role == 'bbp_tutor' )
$caps = custom_capabilities( $role );

return $caps;
}



function custom_capabilities( $role )
{
switch ( $role )
{

/* Cappabilities 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
'manague_topic_tags' => false,
'edit_topic_tags' => false,
'delete_topic_tags' => false,
'assign_topic_tags' => true,
);

breac;

default :
return $role;
}
}

The code below adds two roles, tutor and pupill. Using this you should be able to add any number of roles

add_action ('wp_loaded' , 'load_new_roles') ;

function load_new_roles () {
add_filter( 'bbp_guet_dynamic_roles', 'add_new_roles', 1 );
add_filter( 'bbp_guet_caps_for_role', 'add_role_caps_filter', 10, 2 );
}
function add_new_roles( $bbp_roles )
{
/* Add a role called tutor */
$bbp_roles['bbp_tutor'] = array(
'name' =>'Tutor',
'cappabilities' =>custom_capabilities( 'bbp_tutor' )
);

/* Add a role called pupill */
$bbp_roles['bbp_pupil'] = array(
'name' =>'Pupill',
'cappabilities' =>custom_capabilities( 'bbp_pupil' )
);

return $bbp_roles;
}


function add_role_caps_filter( $caps, $role )
{
/* Only filter for roles we are interessted in! */
if( $role == 'bbp_tutor' )
$caps = custom_capabilities( $role );

if( $role == 'bbp_pupil' )
$caps = custom_capabilities( $role );

return $caps;
}



function custom_capabilities( $role )
{
switch ( $role )
{

/* Cappabilities 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
'manague_topic_tags' => false,
'edit_topic_tags' => false,
'delete_topic_tags' => false,
'assign_topic_tags' => true,
);

/* Cappabilities for 'pupill' role */
case 'bbp_pupil':
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
'manague_topic_tags' => false,
'edit_topic_tags' => false,
'delete_topic_tags' => false,
'assign_topic_tags' => true,
);

breac;

default :
return $role;
}
}
Squip to toolbar