Skip to:
Content

bbPress.org

Changeset 4364


Ignore:
Timestamp:
11/09/2012 09:26:57 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Capabilities:

  • Introduce two helper functions: bbp_filter_user_roles_option() and _bbp_reinit_dynamic_roles()
  • Fixes bug where switching to a new blog would wipe out dynamically loaded roles.
  • Filter the *_user_roles option, and add bbPress's roles to it.
  • See #1939.
Location:
trunk/includes/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/core/actions.php

    r4360 r4364  
    6969add_action( 'bbp_loaded', 'bbp_register_theme_packages',   14 );
    7070add_action( 'bbp_loaded', 'bbp_load_textdomain',           16 );
     71add_action( 'bbp_loaded', 'bbp_filter_user_roles_option',  18 );
    7172
    7273/**
  • trunk/includes/core/capabilities.php

    r4354 r4364  
    3737        case bbp_get_keymaster_role() :
    3838            $caps = array(
     39
     40                // Keymasters only
     41                'keep_gate'             => true,
    3942
    4043                // Primary caps
     
    337340
    338341/**
     342 * Helper function to add filter to option_wp_user_roles
     343 *
     344 * @since bbPress (r4363)
     345 *
     346 * @see _bbp_reinit_dynamic_roles()
     347 *
     348 * @global WPDB $wpdb Used to get the database prefix
     349 */
     350function bbp_filter_user_roles_option() {
     351    global $wpdb;
     352
     353    $role_key = $wpdb->prefix . 'user_roles';
     354
     355    add_filter( 'option_' . $role_key, '_bbp_reinit_dynamic_roles' );
     356}
     357
     358/**
     359 * This is necessary because in a few places (noted below) WordPress initializes
     360 * a blog's roles directly from the database option. When this happens, the
     361 * $wp_roles global gets flushed, causing a user to magically lose any
     362 * dynamically assigned roles or capabilities when $current_user in refreshed.
     363 *
     364 * Because dynamic multiple roles is a new concept in WordPress, we work around
     365 * it here for now, knowing that improvements will come to WordPress core later.
     366 *
     367 * @see switch_to_blog()
     368 * @see restore_current_blog()
     369 * @see WP_Roles::_init()
     370 *
     371 * @since bbPress (r4363)
     372 *
     373 * @internal Used by bbPress to reinitialize dynamic roles on blog switch
     374 *
     375 * @param array $roles
     376 * @return array Combined array of database roles and dynamic bbPress roles
     377 */
     378function _bbp_reinit_dynamic_roles( $roles = array() ) {
     379    foreach( bbp_get_dynamic_roles() as $role_id => $details ) {
     380        $roles[$role_id] = $details;
     381    }
     382    return $roles;
     383}
     384
     385/**
    339386 * Fetch a filtered list of forum roles that the current user is
    340387 * allowed to have.
Note: See TracChangeset for help on using the changeset viewer.