_bbp_reinit_dynamic_roles

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

Description

(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.

Usage

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

Defined (1)

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

/includes/core/capabilities.php  
  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;