Skip to:

Re: Adding a new User Type

In 1.0 Release Candidate 1, roles change dramatically from 0.9.x. I appreciate there is Role Manager, but I wanted a simple fix for an existing tweak based on Fel’s original code.

The code below creates a new role, adds capabilities that mimic the ‘member’ role, plus extra capabilities you specify.

global $bb_roles; // Get the master list of roles
$key = 'role_internal_name'; // Edit: Name of new role, as used internally by BBPress
$name = __('Role Public Name'); // Edit: Name of new role, as shown in public
$cap = array ( 'view_by_ip', ); // Edit: Add extra capabilities within this array. Must be pre-defined capabilities. Empty if you just wish to apply member capabilities.
$r = new BP_Role(); // New role class
$r->name = $key; // Assign the internal name
$r->capabilities = $bb_roles->role_objects[ 'member' ]->capabilities; // Copies member capabilities to the new role
foreach ( $cap as $add ) $r->capabilities[ $add ] = 1; // Adds extra capabilities
$bb_roles->role_objects[ $key ] = $r; // Adds the new role to $bb_roles
$bb_roles->role_names[ $key ] = $name; // Adds the new role to the list of role names

Hooked using: add_action/add_filter( ‘bb_got_roles’, ‘my_function_name’ );

I have no idea whether this is the most efficient way of doing this. So I’d welcome improvements.

Skip to toolbar