Skip to:
Content

bbPress.org

Changeset 4335


Ignore:
Timestamp:
11/04/2012 09:18:54 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Capabilities:

  • Introduce bbp_get_user_role_map() to more intelligently map WordPress roles to bbPress roles.
  • Use bbp_get_user_role_map() in bbp_set_current_user_default_role().
  • See #1939.
  • Fixes #2010.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/users/capabilities.php

    r4330 r4335  
    112112        return;
    113113
    114     // Assign the default role to the current user
    115     bbpress()->current_user->add_role( bbp_get_default_role() );
     114    // Load up bbPress
     115    $bbp = bbpress();
     116
     117    // Get the current user's WordPress role. Set to empty string if none found.
     118    $user_role = isset( $bbp->current_user->roles ) ? array_shift( $bbp->current_user->roles ) : '';
     119
     120    // Loop through the role map, and grant the proper bbPress role
     121    foreach ( (array) bbp_get_user_role_map() as $wp_role => $bbp_role ) {
     122        if ( $user_role == $wp_role ) {
     123            $bbp->current_user->add_role( $bbp_role );
     124            break;
     125        }
     126    }   
    116127}
     128
     129/**
     130 * Return a map of WordPress roles to bbPress roles. Used to automatically grant
     131 * appropriate bbPress roles to WordPress users that wouldn't already have a
     132 * role in the forums. Also guarantees WordPress admins get the Keymaster role.
     133 *
     134 * @since bbPress (r4334)
     135 *
     136 * @return array Filtered array of WordPress roles to bbPress roles
     137 */
     138function bbp_get_user_role_map() {
     139    return (array) apply_filters( 'bbp_get_user_role_map', array (
     140        'administrator' => bbp_get_keymaster_role(),
     141        'editor'        => bbp_get_participant_role(),
     142        'author'        => bbp_get_participant_role(),
     143        'contributor'   => bbp_get_participant_role(),
     144        'subscriber'    => bbp_get_participant_role(),
     145        ''              => bbp_get_participant_role()
     146    ) );
     147}
Note: See TracChangeset for help on using the changeset viewer.