Skip to:
Content

bbPress.org

Changeset 4308


Ignore:
Timestamp:
11/02/2012 07:58:46 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Capabilities:

  • Update bbp_profile_update_capabilities() to include saving forums roles.
  • When saving a role, remove any individual forums capabilities that were set.
  • Add some legacy caps to primary group, so they are correctly removed.
  • See #1939.
File:
1 edited

Legend:

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

    r4249 r4308  
    1919function bbp_get_primary_capabilities() {
    2020        return apply_filters( 'bbp_get_primary_capabilities', array(
     21
     22                // Current caps
     23                'spectate',
    2124                'participate',
    2225                'moderate',
    2326                'throttle',
    24                 'view_trash'
     27                'view_trash',
     28
     29                // Legacy caps
     30                'banned',
     31                'blocked',
     32                'bozo'
    2533        ) );
    2634}
     
    4351        switch ( $cap ) {
    4452
    45                 /**
    46                  * The 'participate' capability is similar to WordPress's 'read' cap,
    47                  * in that it is the minimum required cap to perform any other bbPress
    48                  * related thing.
    49                  */
     53                // Minimum required cap to read any forum content
     54                case 'spectate' :
     55
     56                // Minimum required cap to create any forum content
    5057                case 'participate' :
    5158
     
    6471
    6572                        break;
    66                        
     73
    6774                case 'moderate' :
    6875
     
    136143
    137144        // Add caps for the first role
    138         foreach ( $caps as $cap )
    139                 $user->add_cap( $cap, true );
     145        foreach ( $caps as $cap => $value )
     146                $user->add_cap( $cap, $value );
    140147
    141148        // Success
     
    193200 * @usse bbp_save_user_caps() to save caps
    194201 */
    195 function bbp_edit_user_profile_update_capabilities( $user_id = 0 ) {
     202function bbp_profile_update_capabilities( $user_id = 0 ) {
    196203
    197204        // Bail if no user ID was passed
     
    199206                return;
    200207
    201         // Either reset caps for role
    202         if ( ! empty( $_POST['bbp-default-caps'] ) ) {
    203                 bbp_reset_user_caps( $user_id );
    204 
    205         // Or set caps individually
    206         } else {
    207                 bbp_save_user_caps( $user_id );
     208        // Bail if advanced capability editor is off
     209        if ( ! empty( $_POST['bbp-forums-role'] ) ) {
     210
     211                // Fromus role we want the user to have
     212                $new_role    = stripslashes( $_POST['bbp-forums-role'] );
     213                $forums_role = bbp_get_user_role( $user_id );
     214
     215                // Set the new forums role
     216                if ( $new_role != $forums_role ) {
     217                        bbp_set_user_role( $user_id, $new_role );
     218                }
     219
     220                // Remove any interim form user capabilities
     221                bbp_remove_user_caps( $user_id );
     222        }
     223
     224        // Save additional capabilities
     225        if ( bbp_use_advanced_capability_editor() ) {
     226
     227                // Either reset caps for role
     228                if ( ! empty( $_POST['bbp-default-caps'] ) ) {
     229                        bbp_reset_user_caps( $user_id );
     230
     231                // Or set caps individually
     232                } else {
     233                        bbp_save_user_caps( $user_id );
     234                }
    208235        }
    209236}
     
    240267
    241268        // Assign the default role to the current user
    242         bbpress()->current_user->set_role( get_option( 'default_role', 'subscriber' ) );
    243 }
     269        bbpress()->current_user->add_role( bbp_get_default_role() );
     270}
Note: See TracChangeset for help on using the changeset viewer.