This is necessary because in a few places (noted below) WordPress initializes a blog's roles directly from the database option.


(array) _bbp_reinit_dynamic_roles( (array) $roles = array() ); 

When this happens, the $wp_roles global gets flushed, causing a user to magically lose any dynamically assigned roles or capabilities when $current_user in refreshed.

Because dynamic multiple roles is a new concept in WordPress, we work around it here for now, knowing that improvements will come to WordPress core later.

Also note that if using the $wp_user_roles global non-database approach, bbPress does not have an intercept point to add its dynamic roles.

Returns (array)

Combined array of database roles and dynamic bbPress roles

Parameters (1)

0. $roles — Optional. (array) => array()
The roles.


  1. if ( !function_exists( '_bbp_reinit_dynamic_roles' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/core/capabilities.php'; 
  4. // The roles. 
  5. $roles = array(); 
  7. // NOTICE! Understand what this does before running. 
  8. $result = _bbp_reinit_dynamic_roles($roles); 

Defined (1)

The function is defined in the following location(s).

  1. function _bbp_reinit_dynamic_roles( $roles = array() ) { 
  2. foreach ( bbp_get_dynamic_roles() as $role_id => $details ) { 
  3. $roles[$role_id] = $details; 
  4. return $roles;