Skip to:
Content

bbPress.org

Changeset 4349


Ignore:
Timestamp:
11/07/2012 08:04:06 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Capabilities:

  • Remove most capability mappings to 'participate' cap.
  • Update bbp_set_current_user_default_role() to dynamically map a logged in user if global access is turned off.
  • Provides alternative to users being granted a database role without taking any action.
  • This makes bbPress work similarly to comments, though a decision needs to be made regarding profile pages for these "anonymous" users.
Location:
trunk/includes
Files:
4 edited

Legend:

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

    r4330 r4349  
    33/**
    44 * bbPress Forum Capabilites
    5  * 
     5 *
    66 * Used to map forum capabilities to WordPress's existing capabilities.
    77 *
     
    5454        case 'read_hidden_forums'  :
    5555
    56             // Non-participants can never read private/hidden forums
    57             if ( ! user_can( $user_id, 'participate' ) ) {
    58                 $caps = array( 'do_not_allow' );
    59 
    6056            // Moderators can always read private/hidden forums
    61             } elseif ( user_can( $user_id, 'moderate' ) ) {
    62                 $caps = array( $cap );
     57            if ( user_can( $user_id, 'moderate' ) ) {
     58                $caps = array( 'moderate' );
    6359            }
    6460
     
    6864
    6965            // User cannot participate
    70             if ( ! user_can( $user_id, 'participate' ) ) {
     66            if ( ! user_can( $user_id, 'spectate' ) ) {
    7167                $caps = array( 'do_not_allow' );
    7268
    7369            // Do some post ID based logic
    7470            } else {
    75            
     71
    7672                // Get the post
    7773                $_post = get_post( $args[0] );
     
    8379                    // Post is public
    8480                    if ( bbp_get_public_status_id() == $_post->post_status ) {
    85                         $caps = array( 'particpate' );
     81                        $caps = array( 'spectate' );
    8682
    8783                    // User is author so allow read
    8884                    } elseif ( (int) $user_id == (int) $_post->post_author ) {
    89                         $caps = array( 'participate' );
     85                        $caps = array( 'spectate' );
    9086
    9187                    // Unknown so map to private posts
     
    10298        case 'publish_forums'  :
    10399
    104             // Non participants cannot participate
    105             if ( ! user_can( $user_id, 'participate' ) ) {
    106                 $caps = array( 'do_not_allow' );
    107 
    108100            // Moderators can always edit
    109             } elseif ( user_can( $user_id, 'moderate' ) ) {
    110                 $caps = array( $cap );
     101            if ( user_can( $user_id, 'moderate' ) ) {
     102                $caps = array( 'moderate' );
    111103            }
    112104
     
    119111        case 'edit_others_forums'  :
    120112
    121             // Non participants cannot manage content
    122             if ( ! user_can( $user_id, 'participate' ) ) {
    123                 $caps = array( 'do_not_allow' );
    124 
    125113            // Moderators can always edit
    126             } elseif ( user_can( $user_id, 'moderate' ) ) {
    127                 $caps = array( $cap );
     114            if ( user_can( $user_id, 'moderate' ) ) {
     115                $caps = array( 'moderate' );
    128116            }
    129117
  • trunk/includes/replies/capabilities.php

    r4330 r4349  
    33/**
    44 * bbPress Reply Capabilites
    5  * 
     5 *
    66 * Used to map reply capabilities to WordPress's existing capabilities.
    77 *
     
    5353
    5454            // User cannot participate
    55             if ( ! user_can( $user_id, 'participate' ) ) {
     55            if ( ! user_can( $user_id, 'spectate' ) ) {
    5656                $caps = array( 'do_not_allow' );
    5757
    5858            // Do some post ID based logic
    5959            } else {
    60            
     60
    6161                // Get the post
    6262                $_post = get_post( $args[0] );
     
    6868                    // Post is public
    6969                    if ( bbp_get_public_status_id() == $_post->post_status ) {
    70                         $caps = array( 'particpate' );
     70                        $caps = array( 'spectate' );
    7171
    7272                    // User is author so allow read
    7373                    } elseif ( (int) $user_id == (int) $_post->post_author ) {
    74                         $caps = array( 'participate' );
     74                        $caps = array( 'spectate' );
    7575
    7676                    // Unknown so map to private posts
     
    8787        case 'publish_replies' :
    8888
    89             // Non participants cannot participate
    90             if ( ! user_can( $user_id, 'participate' ) ) {
    91                 $caps = array( 'do_not_allow' );
    92 
    9389            // Moderators can always publish
    94             } elseif ( user_can( $user_id, 'moderate' ) ) {
    95                 $caps = array( $cap );
     90            if ( user_can( $user_id, 'moderate' ) ) {
     91                $caps = array( 'moderate' );
    9692            }
    9793
     
    104100        case 'edit_others_replies' :
    105101
    106             // Non participants cannot manage content
    107             if ( ! user_can( $user_id, 'participate' ) ) {
    108                 $caps = array( 'do_not_allow' );
    109 
    110102            // Moderators can always edit
    111             } elseif ( user_can( $user_id, 'moderate' ) ) {
    112                 $caps = array( $cap );
     103            if ( user_can( $user_id, 'moderate' ) ) {
     104                $caps = array( 'moderate' );
    113105            }
    114106
     
    160152                // Moderators can always edit forum content
    161153                } elseif ( user_can( $user_id, 'moderate' ) ) {
    162                     $caps[] = 'participate';
     154                    $caps[] = 'moderate';
    163155
    164156                // Unknown so map to delete_others_posts
     
    169161
    170162            break;
    171            
     163
    172164        // Moderation override
    173165        case 'delete_replies'        :
    174166        case 'delete_others_replies' :
    175167
    176             // Non participants cannot manage content
    177             if ( ! user_can( $user_id, 'participate' ) ) {
    178                 $caps = array( 'do_not_allow' );
    179 
    180168            // Moderators can always delete
    181             } elseif ( user_can( $user_id, 'moderate' ) ) {
    182                 $caps = array( $cap );
     169            if ( user_can( $user_id, 'moderate' ) ) {
     170                $caps = array( 'moderate' );
    183171            }
    184172
    185173            break;
    186            
     174
    187175        /** Admin *************************************************************/
    188176
  • trunk/includes/topics/capabilities.php

    r4330 r4349  
    33/**
    44 * bbPress Topic Capabilites
    5  * 
     5 *
    66 * Used to map topic capabilities to WordPress's existing capabilities.
    77 *
     
    7171
    7272            // User cannot participate
    73             if ( ! user_can( $user_id, 'participate' ) ) {
     73            if ( ! user_can( $user_id, 'spectate' ) ) {
    7474                $caps = array( 'do_not_allow' );
    7575
    7676            // Do some post ID based logic
    7777            } else {
    78            
     78
    7979                // Get the post
    8080                $_post = get_post( $args[0] );
     
    8686                    // Post is public
    8787                    if ( bbp_get_public_status_id() == $_post->post_status ) {
    88                         $caps = array( 'particpate' );
     88                        $caps = array( 'spectate' );
    8989
    9090                    // User is author so allow read
    9191                    } elseif ( (int) $user_id == (int) $_post->post_author ) {
    92                         $caps = array( 'participate' );
     92                        $caps = array( 'spectate' );
    9393
    9494                    // Unknown so map to private posts
     
    105105        case 'publish_topics'  :
    106106
    107             // Non participants cannot participate
    108             if ( ! user_can( $user_id, 'participate' ) ) {
    109                 $caps = array( 'do_not_allow' );
    110 
    111107            // Moderators can always publish
    112             } elseif ( user_can( $user_id, 'moderate' ) ) {
    113                 $caps = array( $cap );
     108            if ( user_can( $user_id, 'moderate' ) ) {
     109                $caps = array( 'moderate' );
    114110            }
    115111
     
    122118        case 'edit_others_topics' :
    123119
    124             // Non participants cannot manage content
    125             if ( ! user_can( $user_id, 'participate' ) ) {
    126                 $caps = array( 'do_not_allow' );
    127 
    128120            // Moderators can always edit
    129             } elseif ( user_can( $user_id, 'moderate' ) ) {
     121            if ( user_can( $user_id, 'moderate' ) ) {
    130122                $caps = array( $cap );
    131123            }
     
    178170                // Moderators can always edit forum content
    179171                } elseif ( user_can( $user_id, 'moderate' ) ) {
    180                     $caps[] = 'participate';
     172                    $caps[] = 'moderate';
    181173
    182174                // Unknown so map to delete_others_posts
     
    187179
    188180            break;
    189            
     181
    190182        // Moderation override
    191183        case 'delete_topics'         :
    192184        case 'delete_others_topics'  :
    193185
    194             // Non participants cannot manage content
    195             if ( ! user_can( $user_id, 'participate' ) ) {
    196                 $caps = array( 'do_not_allow' );
    197 
    198186            // Moderators can always delete
    199             } elseif ( user_can( $user_id, 'moderate' ) ) {
     187            if ( user_can( $user_id, 'moderate' ) ) {
    200188                $caps = array( $cap );
    201189            }
    202190
    203191            break;
    204            
     192
    205193        /** Admin *************************************************************/
    206194
     
    229217    // What capability is being checked?
    230218    switch ( $cap ) {
    231         case 'manage_topic_tags' :
    232         case 'edit_topic_tags'   :
    233         case 'delete_topic_tags' :
    234         case 'assign_topic_tags' :
    235 
    236             // Non participants cannot manage content
    237             if ( ! user_can( $user_id, 'participate' ) ) {
    238                 $caps = array( 'do_not_allow' );
     219        case 'manage_topic_tags'    :
     220        case 'edit_topic_tags'      :
     221        case 'delete_topic_tags'    :
     222        case 'assign_topic_tags'    :
     223        case 'bbp_topic_tags_admin' :
    239224
    240225            // Moderators can always edit
    241             } elseif ( user_can( $user_id, 'moderate' ) ) {
    242                 $caps = array( $cap );
    243             }
    244 
    245             break;
    246 
    247         case 'bbp_topic_tags_admin' :
    248             $caps = array( 'moderate' );
     226            if ( user_can( $user_id, 'moderate' ) ) {
     227                $caps = array( 'moderate' );
     228            }
    249229    }
    250230
  • trunk/includes/users/capabilities.php

    r4346 r4349  
    33/**
    44 * bbPress User Capabilites
    5  * 
     5 *
    66 * Used to map user capabilities to WordPress's existing capabilities.
    77 *
     
    171171function bbp_set_current_user_default_role() {
    172172
    173     // Bail if forum is not global
    174     if ( ! bbp_allow_global_access( true ) )
    175         return;
     173    /** Sanity ****************************************************************/
    176174
    177175    // Bail if not logged in or already a member of this site
     
    190188        return;
    191189
    192     // Load up bbPress
    193     $bbp = bbpress();
     190    /** Ready *****************************************************************/
     191
     192    // Load up bbPress once
     193    $bbp         = bbpress();
     194
     195    // Get whether or not to add a role to the user account
     196    $add_to_site = bbp_allow_global_access();
    194197
    195198    // Get the current user's WordPress role. Set to empty string if none found.
    196     $user_role = isset( $bbp->current_user->roles ) ? array_shift( $bbp->current_user->roles ) : '';
     199    $user_role   = isset( $bbp->current_user->roles ) ? array_shift( $bbp->current_user->roles ) : '';
    197200
    198201    // Loop through the role map, and grant the proper bbPress role
    199202    foreach ( (array) bbp_get_user_role_map() as $wp_role => $bbp_role ) {
     203
     204        // User's role matches a possible WordPress role (including none at all)
    200205        if ( $user_role == $wp_role ) {
    201             $bbp->current_user->add_role( $bbp_role );
     206
     207            // Add role to user account, making them a user of this site
     208            if ( true == $add_to_site ) {
     209                $bbp->current_user->add_role( $bbp_role );
     210
     211            // Dynamically assign capabilities, making them "anonymous"
     212            } else {
     213                $bbp->current_user->caps[$bbp_role] = true;
     214                $bbp->current_user->get_role_caps();
     215            }
     216
    202217            break;
    203218        }
    204     }   
     219    }
    205220}
    206221
     
    226241        'contributor'   => $default_role,
    227242        'subscriber'    => $default_role,
    228         ''              => $default_role
     243        ''              => bbp_get_anonymous_role()
    229244    ) );
    230245}
     
    490505/**
    491506 * Checks if user is active
    492  * 
     507 *
    493508 * @since bbPress (r3502)
    494  * 
     509 *
    495510 * @uses is_user_logged_in() To check if user is logged in
    496511 * @uses bbp_get_displayed_user_id() To get current user ID
     
    525540/**
    526541 * Checks if user is not active.
    527  * 
     542 *
    528543 * @since bbPress (r3502)
    529  * 
     544 *
    530545 * @uses is_user_logged_in() To check if user is logged in
    531546 * @uses bbp_get_displayed_user_id() To get current user ID
Note: See TracChangeset for help on using the changeset viewer.