Skip to:
Content

bbPress.org

Changeset 4164


Ignore:
Timestamp:
08/21/2012 06:40:18 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Capabilities:

  • Remove roles and move everything to mapped capabilities.
  • First pass at admin-side forum capability manager.
  • Deprecate moderator, anonymous, and participant roles and associated functions.
  • Deprecate add/remove role/cap functions.
  • More cap mapping needed for users that are not explicitly blocked.
  • Adds cap check to forms for topic-tag adding/editing.
  • See #1939
Location:
branches/plugin
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-actions.php

    r4159 r4164  
    6464
    6565// Activation
    66 add_action( 'bbp_activation', 'bbp_activating',     1 );
    67 add_action( 'bbp_activation', 'bbp_add_roles',      1 );
    68 add_action( 'bbp_activation', 'bbp_add_caps',       2 );
    6966add_action( 'bbp_activation', 'bbp_add_options',    1 );
    7067add_action( 'bbp_activation', 'flush_rewrite_rules'   );
    7168
    7269// Deactivation
    73 add_action( 'bbp_deactivation', 'bbp_remove_caps',    1 );
    74 add_action( 'bbp_deactivation', 'bbp_remove_roles',   2 );
    7570add_action( 'bbp_deactivation', 'flush_rewrite_rules'   );
    7671add_action( 'bbp_deactivation', 'bbp_deactivated'       );
    7772
    78 //
    79 add_action( 'bbp_new_site', 'bbp_add_roles',              2 );
    80 add_action( 'bbp_new_site', 'bbp_add_caps',               4 );
     73// New Site
    8174add_action( 'bbp_new_site', 'bbp_add_options',            6 );
    8275add_action( 'bbp_new_site', 'bbp_create_initial_content', 8 );
     
    112105
    113106    // Do the bbPress activation routine
    114     do_action( 'bbp_new_site' );
     107    do_action( 'bbp_new_site', $blog_id, $user_id, $domain, $path, $site_id, $meta );
    115108
    116109    // restore original blog
  • branches/plugin/bbp-admin/bbp-admin.php

    r4159 r4164  
    9898        require( $this->admin_dir . 'bbp-topics.php'    );
    9999        require( $this->admin_dir . 'bbp-replies.php'   );
     100        require( $this->admin_dir . 'bbp-users.php'     );
    100101    }
    101102
     
    11851186            case 'bbpress-update' :
    11861187
    1187                 // @todo more update stuff here, evaluate performance
    1188 
    1189                 // Remove roles and caps
    1190                 bbp_remove_roles();
    1191                 bbp_remove_caps();
    1192 
    1193                 // Make sure roles, capabilities, and options exist
    1194                 bbp_add_roles();
    1195                 bbp_add_caps();
    1196                 bbp_add_options();
    1197 
    1198                 // Ensure any new permalinks are created
    1199                 flush_rewrite_rules();
    1200 
    12011188                // Ensure proper version in the DB
    12021189                bbp_version_bump();
  • branches/plugin/bbp-admin/bbp-converter.php

    r4161 r4164  
    694694        /** User Section ******************************************************/
    695695
    696         $default_role = ( is_multisite() && get_option( '_bbp_allow_global_access' ) ) ? bbp_get_participant_role() : get_option( 'default_role' );
    697696        $this->field_map[] = array(
    698697            'to_type'      => 'user',
    699698            'to_fieldname' => 'role',
    700             'default'      => $default_role
     699            'default'      => get_option( 'default_role' )
    701700        );
    702701    }
  • branches/plugin/bbp-admin/bbp-users.php

    r4053 r4164  
    2121class BBP_Users_Admin {
    2222
    23     /** Variables *************************************************************/
    24 
    25     /** Functions *************************************************************/
    26 
    2723    /**
    2824     * The bbPress users admin loader
     
    3329     * @uses BBP_Users_Admin::setup_actions() Setup the hooks and actions
    3430     */
    35     function __construct() {
    36         $this->setup_globals();
     31    public function __construct() {
    3732        $this->setup_actions();
    3833    }
     
    4742     */
    4843    function setup_actions() {
     44
     45        // Admin styles
     46        add_action( 'admin_head',               array( $this, 'admin_head'          ) );
    4947
    5048        // User profile edit/display actions
     
    5654        add_action( 'edit_user_profile_update', array( $this, 'user_profile_update' ) );
    5755    }
    58 
    59     /**
    60      * Admin globals
    61      *
    62      * @since bbPress (r2646)
    63      * @access private
    64      */
    65     function setup_globals() { }
    6656
    6757    /**
     
    7565     * @uses sanitize_html_class() To sanitize the classes
    7666     */
    77     function admin_head() { }
     67    public function admin_head() {
     68        ?>
     69
     70        <style type="text/css" media="screen">
     71        /*<![CDATA[*/
     72            div.bbp-user-capabilities {
     73                float: left;
     74                margin: 0 20px 0 0;
     75            }
     76            body.rtl div.bbp-user-capabilities {
     77                float: right;
     78                margin: 0 0 0 20px;
     79            }
     80           
     81            div.bbp-user-capabilities h4 {
     82                margin: 0 0 10px;
     83            }
     84           
     85            p.bbp-default-caps-wrapper {
     86                clear: both;
     87                margin: 80px -10px 0;
     88            }
     89        /*]]>*/
     90        </style>
     91
     92        <?php
     93    }
    7894
    7995    /**
     
    86102     * @return bool Always false
    87103     */
    88     function user_profile_update( $user_id ) { }
     104    public function user_profile_update( $user_id ) {
     105
     106        // Bail if no user
     107        if ( empty( $user_id ) )
     108            return;
     109
     110        // Load up the user
     111        $user      = new WP_User( $user_id );
     112        $user_role = bbp_get_user_role( $user_id );
     113
     114        // Either reset caps for role
     115        if ( ! empty( $_POST['bbp-default-caps'] ) ) {
     116
     117            // Remove all caps
     118            foreach ( bbp_get_capability_groups() as $group ) {
     119                foreach ( bbp_get_capabilities_for_group( $group ) as $capability ) {
     120                    $user->remove_cap( $capability );
     121                }
     122            }
     123
     124            // Maybe use users new role
     125            if ( ! empty( $_POST['role'] ) ) {
     126                $new_role = get_role( $_POST['role'] );
     127                $new_role = isset( $new_role->name ) ? $new_role->name : '';
     128
     129                if ( $new_role != $user_role ) {
     130                    $user_role = $new_role;
     131                }
     132            }
     133
     134            // Add back caps for current role
     135            if ( !empty( $user_role ) ) {
     136                foreach ( bbp_get_caps_for_role( $user_role ) as $capability ) {
     137                    $user->add_cap( $capability );
     138                }
     139            }
     140
     141        // Or set caps individually
     142        } else {
     143
     144            // Loop through capability groups
     145            foreach ( bbp_get_capability_groups() as $group ) {
     146
     147                // Loop through capabilities
     148                foreach ( bbp_get_capabilities_for_group( $group ) as $capability ) {
     149
     150                    // Maybe add cap
     151                    if ( ! empty( $_POST['_bbp_' . $capability] ) && ! $user->has_cap( $capability ) ) {
     152                        $user->add_cap( $capability );
     153
     154                    // Maybe remove cap
     155                    } elseif ( empty( $_POST['_bbp_' . $capability] ) && $user->has_cap( $capability ) ) {
     156                        $user->remove_cap( $capability );
     157                    }
     158                }
     159            }
     160        }
     161    }
    89162
    90163    /**
     
    97170     * @return bool Always false
    98171     */
    99     function user_profile_forums( $profileuser ) { }
     172    public function user_profile_forums( $profileuser ) {
     173
     174        // Bail if current user cannot edit users
     175        if ( ! current_user_can( 'edit_user', $profileuser->ID ) )
     176            return;
     177
     178        // Noop WordPress additional caps output area
     179        add_filter( 'additional_capabilities_display', '__return_false' ); ?>
     180
     181        <h3><?php _e( 'Forum Capabilities', 'bbpress' ); ?></h3>
     182
     183        <table class="form-table">
     184            <tbody>
     185                <tr>
     186                    <th><?php _e( 'This user can:', 'bbpress' ); ?></th>
     187
     188                    <td>
     189                        <fieldset>
     190                            <legend class="screen-reader-text"><span><?php _e( 'Additional Capabilities', 'bbpress' ); ?></span></legend>
     191
     192                            <?php foreach ( bbp_get_capability_groups() as $group ) : ?>
     193
     194                                <div class="bbp-user-capabilities">
     195                                    <h4><?php bbp_capability_group_title( $group ); ?></h4>
     196
     197                                    <?php foreach ( bbp_get_capabilities_for_group( $group ) as $capability ) : ?>
     198
     199                                        <label for="_bbp_<?php echo $capability; ?>">
     200                                            <input id="_bbp_<?php echo $capability; ?>" name="_bbp_<?php echo $capability; ?>" type="checkbox" id="_bbp_<?php echo $capability; ?>" value="1" <?php checked( user_can( $profileuser->ID, $capability ) ); ?> />
     201                                            <?php bbp_capability_title( $capability ); ?>
     202                                        </label>
     203                                        <br />
     204
     205                                    <?php endforeach; ?>
     206
     207                                </div>
     208
     209                            <?php endforeach; ?>
     210
     211                            <p class="bbp-default-caps-wrapper">
     212                                <input type="submit" name="bbp-default-caps" class="button" value="<?php _e( 'Reset to Default', 'bbpress' ); ?>"/>
     213                            </p>
     214
     215                        </fieldset>
     216                    </td>
     217                </tr>
     218
     219            </tbody>
     220        </table>
     221
     222        <?php
     223    }
    100224}
     225new BBP_Users_Admin();
    101226endif; // class exists
  • branches/plugin/bbp-includes/bbp-core-caps.php

    r4083 r4164  
    1212
    1313/**
    14  * Adds bbPress-specific user roles.
    15  *
    16  * This is called on plugin activation.
    17  *
    18  * @since bbPress (r2741)
    19  *
    20  * @uses get_option() To get the default role
    21  * @uses get_role() To get the default role object
    22  * @uses add_role() To add our own roles
    23  * @uses do_action() Calls 'bbp_add_roles'
    24  */
    25 function bbp_add_roles() {
    26 
    27     // Get new role names
    28     $moderator_role   = bbp_get_moderator_role();
    29     $participant_role = bbp_get_participant_role();
    30 
    31     // Add the Moderator role and add the default role caps.
    32     // Mod caps are added by the bbp_add_caps() function
    33     $default = get_role( get_option( 'default_role' ) );
    34 
    35     // If role does not exist, default to read cap
    36     if ( empty( $default->capabilities ) )
    37         $default->capabilities = array( 'read' );
    38 
    39     // Moderators are default role + forum moderating caps in bbp_add_caps()
    40     add_role( $moderator_role,   'Forum Moderator',   $default->capabilities );
    41 
    42     // Forum Subscribers are auto added to sites with global forums
    43     add_role( $participant_role, 'Forum Participant', $default->capabilities );
    44 
    45     do_action( 'bbp_add_roles' );
    46 }
    47 
    48 /**
    49  * Adds capabilities to WordPress user roles.
    50  *
    51  * This is called on plugin activation.
    52  *
    53  * @since bbPress (r2608)
    54  *
    55  * @uses get_role() To get the administrator, default and moderator roles
    56  * @uses WP_Role::add_cap() To add various capabilities
    57  * @uses do_action() Calls 'bbp_add_caps'
    58  */
    59 function bbp_add_caps() {
    60     global $wp_roles;
    61 
    62     // Load roles if not set
    63     if ( ! isset( $wp_roles ) )
    64         $wp_roles = new WP_Roles();
    65 
    66     // Loop through available roles
    67     foreach( $wp_roles->roles as $role => $details ) {
    68 
    69         // Load this role
    70         $this_role = get_role( $role );
    71 
    72         // Loop through caps for this role and remove them
    73         foreach ( bbp_get_caps_for_role( $role ) as $cap ) {
    74             $this_role->add_cap( $cap );
     14 * Get the capability groups
     15 *
     16 * @since bbPress (r4163)
     17 *
     18 * @return array of groups
     19 */
     20function bbp_get_capability_groups() {
     21    return apply_filters( 'bbp_get_capability_groups', array(
     22        'general',
     23        'forums',
     24        'topics',
     25        'replies',
     26        'topic_tags'
     27    ) );
     28}
     29
     30/**
     31 * Get capabilities for the group
     32 *
     33 * @since bbPress (r4163)
     34 *
     35 * @param string $group
     36 * @return array of capabilities
     37 */
     38function bbp_get_capabilities_for_group( $group = '' ) {
     39    switch ( $group ) {
     40        case 'general'    :
     41            return bbp_get_general_capabilities();
     42            break;
     43        case 'forums'     :
     44            return bbp_get_forums_capabilities();
     45            break;
     46        case 'topics'     :
     47            return bbp_get_topics_capabilities();
     48            break;
     49        case 'replies'    :
     50            return bbp_get_replies_capabilities();
     51            break;
     52        case 'topic_tags' :
     53            return bbp_get_topic_tags_capabilities();
     54            break;
     55        default :
     56            return array();
     57            break;
     58    }
     59}
     60
     61/**
     62 * Get the general forum capabilities
     63 *
     64 * @since bbPress (r4163)
     65 *
     66 * @return array of general capabilities
     67 */
     68function bbp_get_general_capabilities() {
     69    return apply_filters( 'bbp_get_general_capabilities', array(
     70        'moderate',
     71        'throttle',
     72        'view_trash',
     73        'bozo',
     74        'blocked'
     75    ) );
     76}
     77
     78/**
     79 * Get the forum post-type capabilities
     80 *
     81 * @since bbPress (r4163)
     82 *
     83 * @return array of forums capabilities
     84 */
     85function bbp_get_forums_capabilities() {
     86    return apply_filters( 'bbp_get_forums_capabilities', array(
     87        'publish_forums',
     88        'edit_forums',
     89        'edit_others_forums',
     90        'delete_forums',
     91        'delete_others_forums',
     92        'read_private_forums',
     93        'read_hidden_forums'
     94    ) );
     95}
     96
     97/**
     98 * Get the topic post-type capabilities
     99 *
     100 * @since bbPress (r4163)
     101 *
     102 * @return array of topics capabilities
     103 */
     104function bbp_get_topics_capabilities() {
     105    return apply_filters( 'bbp_get_topics_capabilities', array(
     106        'publish_topics',
     107        'edit_topics',
     108        'edit_others_topics',
     109        'delete_topics',
     110        'delete_others_topics',
     111        'read_private_topics'
     112    ) );
     113}
     114
     115/**
     116 * Get the topic-tag taxonomy capabilities
     117 *
     118 * @since bbPress (r4163)
     119 *
     120 * @return array of topic-tag capabilities
     121 */
     122function bbp_get_topic_tags_capabilities() {
     123    return apply_filters( 'bbp_get_topic_tags_capabilities', array(
     124        'manage_topic_tags',
     125        'edit_topic_tags',
     126        'delete_topic_tags',
     127        'assign_topic_tags'
     128    ) );
     129}
     130
     131/**
     132 * Get the reply post-type capabilities
     133 *
     134 * @since bbPress (r4163)
     135 *
     136 * @return array of replies capabilities
     137 */
     138function bbp_get_replies_capabilities() {
     139    return apply_filters( 'bbp_get_replies_capabilities', array(
     140        'publish_replies',
     141        'edit_replies',
     142        'edit_others_replies',
     143        'delete_replies',
     144        'delete_others_replies',
     145        'read_private_replies'
     146    ) );
     147}
     148
     149/** Output ********************************************************************/
     150
     151/**
     152 * Output the human readable capability group title
     153 *
     154 * @since bbPress (r4163)
     155 *
     156 * @param string $group
     157 * @uses bbp_get_capability_group_title()
     158 */
     159function bbp_capability_group_title( $group = '' ) {
     160    echo bbp_get_capability_group_title( $group );
     161}
     162    /**
     163     * Return the human readable capability group title
     164     *
     165     * @since bbPress (r4163)
     166     *
     167     * @param string $group
     168     * @return string
     169     */
     170    function bbp_get_capability_group_title( $group = '' ) {
     171
     172        // Default return value to capability group
     173        $retval = $group;
     174
     175        switch( $group ) {
     176            case 'general' :
     177                $retval = __( 'General capabilities', 'bbpress' );
     178                break;
     179            case 'forums' :
     180                $retval = __( 'Forum capabilities', 'bbpress' );
     181                break;
     182            case 'topics' :
     183                $retval = __( 'Topic capabilites', 'bbpress' );
     184                break;
     185            case 'topic_tags' :
     186                $retval = __( 'Topic tag capabilities', 'bbpress' );
     187                break;
     188            case 'replies' :
     189                $retval = __( 'Reply capabilities', 'bbpress' );
     190                break;
    75191        }
     192
     193        return apply_filters( 'bbp_get_capability_group_title', $retval, $group );
    76194    }
    77195
    78     do_action( 'bbp_add_caps' );
    79 }
    80 
    81 /**
    82  * Removes capabilities from WordPress user roles.
    83  *
    84  * This is called on plugin deactivation.
    85  *
    86  * @since bbPress (r2608)
    87  *
    88  * @uses get_role() To get the administrator and default roles
    89  * @uses WP_Role::remove_cap() To remove various capabilities
    90  * @uses do_action() Calls 'bbp_remove_caps'
    91  */
    92 function bbp_remove_caps() {
    93     global $wp_roles;
    94 
    95     // Load roles if not set
    96     if ( ! isset( $wp_roles ) )
    97         $wp_roles = new WP_Roles();
    98 
    99     // Loop through available roles
    100     foreach( $wp_roles->roles as $role => $details ) {
    101 
    102         // Load this role
    103         $this_role = get_role( $role );
    104 
    105         // Loop through caps for this role and remove them
    106         foreach ( bbp_get_caps_for_role( $role ) as $cap ) {
    107             $this_role->remove_cap( $cap );
     196/**
     197 * Output the human readable capability title
     198 *
     199 * @since bbPress (r4163)
     200 *
     201 * @param string $group
     202 * @uses bbp_get_capability_title()
     203 */
     204function bbp_capability_title( $capability = '' ) {
     205    echo bbp_get_capability_title( $capability );
     206}
     207    /**
     208     * Return the human readable capability title
     209     *
     210     * @since bbPress (r4163)
     211     *
     212     * @param string $capability
     213     * @return string
     214     */
     215    function bbp_get_capability_title( $capability = '' ) {
     216
     217        // Default return value to capability
     218        $retval = $capability;
     219
     220        switch( $capability ) {
     221
     222            // Misc
     223            case 'moderate' :
     224                $retval = __( 'Moderate entire forum', 'bbpress' );
     225                break;
     226            case 'throttle' :
     227                $retval = __( 'Skip forum throttle check', 'bbpress' );
     228                break;
     229            case 'view_trash' :
     230                $retval = __( 'View items in forum trash', 'bbpress' );
     231                break;
     232            case 'bozo' :
     233                $retval = __( 'User is a forum bozo', 'bbpress' );
     234                break;
     235            case 'blocked' :
     236                $retval = __( 'User is blocked', 'bbpress' );
     237                break;
     238
     239            // Forum caps
     240            case 'read_forum' :
     241                $retval = __( 'View forum', 'bbpress' );
     242                break;
     243
     244            case 'edit_forum' :
     245                $retval = __( 'Edit forum', 'bbpress' );
     246                break;
     247            case 'trash_forum' :
     248                $retval = __( 'Trash forum', 'bbpress' );
     249                break;
     250            case 'delete_forum' :
     251                $retval = __( 'Delete forum', 'bbpress' );
     252                break;
     253            case 'moderate_forum' :
     254                $retval = __( 'Moderate forum', 'bbpress' );
     255                break;
     256            case 'publish_forums' :
     257                $retval = __( 'Create forums', 'bbpress' );
     258                break;
     259            case 'edit_forums' :
     260                $retval = __( 'Edit their own forums', 'bbpress' );
     261                break;
     262            case 'edit_others_forums' :
     263                $retval = __( 'Edit all forums', 'bbpress' );
     264                break;
     265            case 'delete_forums' :
     266                $retval = __( 'Delete their own forums', 'bbpress' );
     267                break;
     268            case 'delete_others_forums' :
     269                $retval = __( 'Delete all forums', 'bbpress' );
     270                break;
     271            case 'read_private_forums' :
     272                $retval = __( 'View private forums', 'bbpress' );
     273                break;
     274            case 'read_hidden_forums' :
     275                $retval = __( 'View hidden forums', 'bbpress' );
     276                break;
     277
     278            // Topic caps
     279            case 'read_topic' :
     280                $retval = __( 'View topic', 'bbpress' );
     281                break;
     282            case 'edit_topic' :
     283                $retval = __( 'Edit topic', 'bbpress' );
     284                break;
     285            case 'trash_topic' :
     286                $retval = __( 'Trash topic', 'bbpress' );
     287                break;
     288            case 'moderate_topic' :
     289                $retval = __( 'Moderate topic', 'bbpress' );
     290                break;
     291            case 'delete_topic' :
     292                $retval = __( 'Delete topic', 'bbpress' );
     293                break;
     294            case 'publish_topics' :
     295                $retval = __( 'Create topics', 'bbpress' );
     296                break;
     297            case 'edit_topics' :
     298                $retval = __( 'Edit their own topics', 'bbpress' );
     299                break;
     300            case 'edit_others_topics' :
     301                $retval = __( 'Edit others topics', 'bbpress' );
     302                break;
     303            case 'delete_topics' :
     304                $retval = __( 'Delete own topics', 'bbpress' );
     305                break;
     306            case 'delete_others_topics' :
     307                $retval = __( 'Delete others topics', 'bbpress' );
     308                break;
     309            case 'read_private_topics' :
     310                $retval = __( 'View private topics', 'bbpress' );
     311                break;
     312
     313            // Reply caps
     314            case 'read_reply' :
     315                $retval = __( 'Read reply', 'bbpress' );
     316                break;
     317            case 'edit_reply' :
     318                $retval = __( 'Edit reply', 'bbpress' );
     319                break;
     320            case 'trash_reply' :
     321                $retval = __( 'Trash reply', 'bbpress' );
     322                break;
     323            case 'delete_reply' :
     324                $retval = __( 'Delete reply', 'bbpress' );
     325                break;
     326            case 'publish_replies' :
     327                $retval = __( 'Create replies', 'bbpress' );
     328                break;
     329            case 'edit_replies' :
     330                $retval = __( 'Edit own replies', 'bbpress' );
     331                break;
     332            case 'edit_others_replies' :
     333                $retval = __( 'Edit others replies', 'bbpress' );
     334                break;
     335            case 'delete_replies' :
     336                $retval = __( 'Delete own replies', 'bbpress' );
     337                break;
     338            case 'delete_others_replies' :
     339                $retval = __( 'Delete others replies', 'bbpress' );
     340                break;
     341            case 'read_private_replies' :
     342                $retval = __( 'View private replies', 'bbpress' );
     343                break;
     344
     345            // Topic tag caps
     346            case 'manage_topic_tags' :
     347                $retval = __( 'Remove tags from topics', 'bbpress' );
     348                break;
     349            case 'edit_topic_tags' :
     350                $retval = __( 'Edit topic tags', 'bbpress' );
     351                break;
     352            case 'delete_topic_tags' :
     353                $retval = __( 'Delete topic tags', 'bbpress' );
     354                break;
     355            case 'assign_topic_tags' :
     356                $retval = __( 'Assign tags to topics', 'bbpress' );
     357                break;
    108358        }
     359
     360        return apply_filters( 'bbp_get_capability_title', $retval, $capability );
    109361    }
    110 
    111     do_action( 'bbp_remove_caps' );
    112 }
    113 
    114 /**
    115  * Removes bbPress-specific user roles.
    116  *
    117  * This is called on plugin deactivation.
    118  *
    119  * @since bbPress (r2741)
    120  *
    121  * @uses remove_role() To remove our roles
    122  * @uses do_action() Calls 'bbp_remove_roles'
    123  */
    124 function bbp_remove_roles() {
    125 
    126     // Get new role names
    127     $moderator_role   = bbp_get_moderator_role();
    128     $participant_role = bbp_get_participant_role();
    129 
    130     // Remove the Moderator role
    131     remove_role( $moderator_role );
    132 
    133     // Remove the Moderator role
    134     remove_role( $participant_role );
    135 
    136     do_action( 'bbp_remove_roles' );
    137 }
    138362
    139363/**
     
    297521}
    298522
     523/** Post Types and Taxonomies *************************************************/
     524
    299525/**
    300526 * Return forum capabilities
     
    306532 */
    307533function bbp_get_forum_caps() {
    308 
    309     // Forum meta caps
    310     $caps = array (
     534    return apply_filters( 'bbp_get_forum_caps', array (
     535        'edit_posts'          => 'edit_forums',
     536        'edit_others_posts'   => 'edit_others_forums',
     537        'publish_posts'       => 'publish_forums',
     538        'read_private_posts'  => 'read_private_forums',
     539        'read_hidden_posts'   => 'read_hidden_forums',
    311540        'delete_posts'        => 'delete_forums',
    312541        'delete_others_posts' => 'delete_others_forums'
    313     );
    314 
    315     return apply_filters( 'bbp_get_forum_caps', $caps );
     542    ) );
    316543}
    317544
     
    325552 */
    326553function bbp_get_topic_caps() {
    327 
    328     // Topic meta caps
    329     $caps = array (
     554    return apply_filters( 'bbp_get_topic_caps', array (
     555        'edit_posts'          => 'edit_topics',
     556        'edit_others_posts'   => 'edit_others_topics',
     557        'publish_posts'       => 'publish_topics',
     558        'read_private_posts'  => 'read_private_topics',
     559        'read_hidden_posts'   => 'read_hidden_topics',
    330560        'delete_posts'        => 'delete_topics',
    331561        'delete_others_posts' => 'delete_others_topics'
    332     );
    333 
    334     return apply_filters( 'bbp_get_topic_caps', $caps );
     562    ) );
    335563}
    336564
     
    343571 * @return array Reply capabilities
    344572 */
    345 function bbp_get_reply_caps () {
    346 
    347     // Reply meta caps
    348     $caps = array (
     573function bbp_get_reply_caps() {
     574    return apply_filters( 'bbp_get_reply_caps', array (
    349575        'edit_posts'          => 'edit_replies',
    350576        'edit_others_posts'   => 'edit_others_replies',
     
    353579        'delete_posts'        => 'delete_replies',
    354580        'delete_others_posts' => 'delete_others_replies'
    355     );
    356 
    357     return apply_filters( 'bbp_get_reply_caps', $caps );
     581    ) );
    358582}
    359583
     
    366590 * @return array Topic tag capabilities
    367591 */
    368 function bbp_get_topic_tag_caps () {
    369 
    370     // Topic tag meta caps
    371     $caps = array (
     592function bbp_get_topic_tag_caps() {
     593    return apply_filters( 'bbp_get_topic_tag_caps', array (
    372594        'manage_terms' => 'manage_topic_tags',
    373595        'edit_terms'   => 'edit_topic_tags',
    374596        'delete_terms' => 'delete_topic_tags',
    375597        'assign_terms' => 'assign_topic_tags'
    376     );
    377 
    378     return apply_filters( 'bbp_get_topic_tag_caps', $caps );
    379 }
    380 
     598    ) );
     599}
     600
     601/** Roles *********************************************************************/
    381602
    382603/**
     
    392613function bbp_get_caps_for_role( $role = '' ) {
    393614
     615    // No role
     616    if ( empty( $role ) ) {
     617        $caps = array(
     618            'blocked'
     619        );
     620
    394621    // Which role are we looking for?
    395     switch ( $role ) {
    396 
    397         // Administrator
    398         case 'administrator' :
    399 
    400             $caps = array(
    401 
    402                 // Forum caps
    403                 'publish_forums',
    404                 'edit_forums',
    405                 'edit_others_forums',
    406                 'delete_forums',
    407                 'delete_others_forums',
    408                 'read_private_forums',
    409                 'read_hidden_forums',
    410 
    411                 // Topic caps
    412                 'publish_topics',
    413                 'edit_topics',
    414                 'edit_others_topics',
    415                 'delete_topics',
    416                 'delete_others_topics',
    417                 'read_private_topics',
    418 
    419                 // Reply caps
    420                 'publish_replies',
    421                 'edit_replies',
    422                 'edit_others_replies',
    423                 'delete_replies',
    424                 'delete_others_replies',
    425                 'read_private_replies',
    426 
    427                 // Topic tag caps
    428                 'manage_topic_tags',
    429                 'edit_topic_tags',
    430                 'delete_topic_tags',
    431                 'assign_topic_tags',
    432 
    433                 // Misc
    434                 'moderate',
    435                 'throttle',
    436                 'view_trash'
    437             );
    438 
    439             break;
    440 
    441         // Moderator
    442         case bbp_get_moderator_role() :
    443 
    444             $caps = array(
    445 
    446                 // Forum caps
    447                 'read_private_forums',
    448                 'read_hidden_forums',
    449 
    450                 // Topic caps
    451                 'publish_topics',
    452                 'edit_topics',
    453                 'edit_others_topics',
    454                 'delete_topics',
    455                 'delete_others_topics',
    456                 'read_private_topics',
    457 
    458                 // Reply caps
    459                 'publish_replies',
    460                 'edit_replies',
    461                 'edit_others_replies',
    462                 'delete_replies',
    463                 'delete_others_replies',
    464                 'read_private_replies',
    465 
    466                 // Topic tag caps
    467                 'manage_topic_tags',
    468                 'edit_topic_tags',
    469                 'delete_topic_tags',
    470                 'assign_topic_tags',
    471 
    472                 // Misc
    473                 'moderate',
    474                 'throttle',
    475                 'view_trash'
    476             );
    477 
    478             break;
    479 
    480         // WordPress Core Roles
    481         case 'editor'      :
    482         case 'author'      :
    483         case 'contributor' :
    484         case 'subscriber'  :
    485 
    486         // bbPress Participant Role
    487         case bbp_get_participant_role() :
    488 
    489         // Any other role
    490         default :
    491 
    492             $caps = array(
    493 
    494                 // Forum caps
    495                 'read_private_forums',
    496 
    497                 // Topic caps
    498                 'publish_topics',
    499                 'edit_topics',
    500 
    501                 // Reply caps
    502                 'publish_replies',
    503                 'edit_replies',
    504 
    505                 // Topic tag caps
    506                 'assign_topic_tags'
    507             );
    508 
    509             break;
     622    } else {
     623        switch ( $role ) {
     624
     625            // Administrator
     626            case 'administrator' :
     627
     628                $caps = array(
     629
     630                    // Forum caps
     631                    'publish_forums',
     632                    'edit_forums',
     633                    'edit_others_forums',
     634                    'delete_forums',
     635                    'delete_others_forums',
     636                    'read_private_forums',
     637                    'read_hidden_forums',
     638
     639                    // Topic caps
     640                    'publish_topics',
     641                    'edit_topics',
     642                    'edit_others_topics',
     643                    'delete_topics',
     644                    'delete_others_topics',
     645                    'read_private_topics',
     646
     647                    // Reply caps
     648                    'publish_replies',
     649                    'edit_replies',
     650                    'edit_others_replies',
     651                    'delete_replies',
     652                    'delete_others_replies',
     653                    'read_private_replies',
     654
     655                    // Topic tag caps
     656                    'manage_topic_tags',
     657                    'edit_topic_tags',
     658                    'delete_topic_tags',
     659                    'assign_topic_tags',
     660
     661                    // Misc
     662                    'moderate',
     663                    'throttle',
     664                    'view_trash'
     665                );
     666
     667                break;
     668
     669            // Any other role
     670            case 'editor'      :
     671            case 'author'      :
     672            case 'contributor' :
     673            case 'subscriber'  :
     674            default            :
     675                $caps = array(
     676
     677                    // Forum caps
     678                    'read_private_forums',
     679
     680                    // Topic caps
     681                    'publish_topics',
     682                    'edit_topics',
     683
     684                    // Reply caps
     685                    'publish_replies',
     686                    'edit_replies',
     687
     688                    // Topic tag caps
     689                    'assign_topic_tags'
     690                );
     691
     692                break;
     693        }
    510694    }
    511695
     
    514698
    515699/**
    516  * Give a user the default 'Forum Participant' role when creating a topic/reply
    517  * on a site they do not have a role or capability on.
     700 * Give a user the default role when creating a topic/reply on a site they do
     701 * not have a role on.
    518702 *
    519703 * @since bbPress (r3410)
     
    541725        return;
    542726
    543     // Give the user the 'Forum Participant' role
     727    // Give the user the default role
    544728    if ( current_user_can( 'bbp_masked' ) ) {
    545 
    546         // Get the default role
    547         $default_role = bbp_get_participant_role();
    548 
    549         // Set the current users default role
    550         bbpress()->current_user->set_role( $default_role );
     729        bbpress()->current_user->set_role( get_option( 'default_role' ) );
    551730    }
    552 }
    553 
    554 /**
    555  * The participant role for registered users without roles
    556  *
    557  * This is primarily for multisite compatibility when users without roles on
    558  * sites that have global forums enabled want to create topics and replies
    559  *
    560  * @since bbPress (r3860)
    561  *
    562  * @uses apply_filters() Allow override of hardcoded anonymous role
    563  * @return string
    564  */
    565 function bbp_get_anonymous_role() {
    566     return apply_filters( 'bbp_get_anonymous_role', 'bbp_anonymous' );
    567 }
    568 
    569 /**
    570  * The participant role for registered users without roles
    571  *
    572  * This is primarily for multisite compatibility when users without roles on
    573  * sites that have global forums enabled want to create topics and replies
    574  *
    575  * @since bbPress (r3410)
    576  *
    577  * @uses apply_filters() Allow override of hardcoded participant role
    578  * @return string
    579  */
    580 function bbp_get_participant_role() {
    581     return apply_filters( 'bbp_get_participant_role', 'bbp_participant' );
    582 }
    583 
    584 /**
    585  * The moderator role for bbPress users
    586  *
    587  * @since bbPress (r3410)
    588  *
    589  * @param string $role
    590  * @uses apply_filters() Allow override of hardcoded moderator role
    591  * @return string
    592  */
    593 function bbp_get_moderator_role() {
    594     return apply_filters( 'bbp_get_moderator_role', 'bbp_moderator' );
    595731}
    596732
     
    622758        return;
    623759
    624     // Normal user is logged in but has no caps
    625     if ( is_user_logged_in() && !current_user_can( 'read' ) ) {
    626 
    627         // Assign user the minimal participant role to map caps to
    628         $default_role  = bbp_get_participant_role();
     760    // Normal user is logged in but not a member of this site
     761    if ( is_user_logged_in() && ! is_user_member_of_blog() ) {
     762
     763        // Assign user the default role to map caps to
     764        $default_role  = get_option( 'default_role' );
    629765
    630766        // Get bbPress caps for the default role
     
    717853    return (bool) apply_filters( 'bbp_current_user_can_see', (bool) $retval, $component );
    718854}
     855
     856/** Deprecated ****************************************************************/
     857
     858/**
     859 * Adds bbPress-specific user roles.
     860 *
     861 * @since bbPress (r2741)
     862 * @deprecated since version 2.2
     863 */
     864function bbp_add_roles() {
     865    _doing_it_wrong( 'bbp_add_roles', __( 'Special forum roles no longer exist. Use mapped capabilities instead', 'bbpress' ), '2.2' );
     866}
     867
     868/**
     869 * Removes bbPress-specific user roles.
     870 *
     871 * @since bbPress (r2741)
     872 * @deprecated since version 2.2
     873 */
     874function bbp_remove_roles() {
     875    _doing_it_wrong( 'bbp_remove_roles', __( 'Special forum roles no longer exist. Use mapped capabilities instead', 'bbpress' ), '2.2' );
     876}
     877
     878/**
     879 * Adds capabilities to WordPress user roles.
     880 *
     881 * @since bbPress (r2608)
     882 * @deprecated since version 2.2
     883 */
     884function bbp_add_caps() {
     885    _doing_it_wrong( 'bbp_add_roles', __( 'Use mapped capabilities instead', 'bbpress' ), '2.2' );
     886}
     887
     888/**
     889 * Removes capabilities from WordPress user roles.
     890 *
     891 * @since bbPress (r2608)
     892 * @deprecated since version 2.2
     893 */
     894function bbp_remove_caps() {
     895    _doing_it_wrong( 'bbp_remove_caps', __( 'Special forum roles no longer exist. Use mapped capabilities instead', 'bbpress' ), '2.2' );
     896}
     897
     898/**
     899 * The anonymous role for unregistered users
     900 *
     901 * @since bbPress (r3860)
     902 *
     903 * @deprecated since version 2.2
     904 */
     905function bbp_get_anonymous_role() {
     906    _doing_it_wrong( 'bbp_get_anonymous_role', __( 'Special forum roles no longer exist. Use mapped capabilities instead', 'bbpress' ), '2.2' );
     907}
     908
     909/**
     910 * The participant role for registered users without roles
     911 *
     912 * @since bbPress (r3410)
     913 *
     914 * @deprecated since version 2.2
     915 */
     916function bbp_get_participant_role() {
     917    _doing_it_wrong( 'bbp_get_participant_role', __( 'Special forum roles no longer exist. Use mapped capabilities instead', 'bbpress' ), '2.2' );
     918}
     919
     920/**
     921 * The moderator role for bbPress users
     922 *
     923 * @since bbPress (r3410)
     924 *
     925 * @deprecated since version 2.2
     926 */
     927function bbp_get_moderator_role() {
     928    _doing_it_wrong( 'bbp_get_moderator_role', __( 'Special forum roles no longer exist. Use mapped capabilities instead', 'bbpress' ), '2.2' );
     929}
  • branches/plugin/bbp-includes/bbp-core-update.php

    r4153 r4164  
    255255
    256256    // 2.2
    257     if ( $raw_db_version < 220 ) {
    258         // No changes yet
    259     }
    260 }
     257    if ( $raw_db_version < 213 ) {
     258
     259        /**
     260         * Remove Roles and Capabilities
     261         *
     262         * bbPress 2.2 moved roles and capabilities to a completely mapped
     263         * system, allowing any existing user in the network to have any other
     264         * set of forum capabilities, regardless of their existing role(s).
     265         */
     266        global $wp_roles;
     267
     268        // Load roles if not set
     269        if ( ! isset( $wp_roles ) )
     270            $wp_roles = new WP_Roles();
     271
     272        // Loop through available roles
     273        foreach( $wp_roles->roles as $role => $details ) {
     274
     275            // Load this role
     276            $this_role = get_role( $role );
     277
     278            // Loop through caps for this role and remove them
     279            foreach ( bbp_get_caps_for_role( $role ) as $cap ) {
     280                $this_role->remove_cap( $cap );
     281            }
     282        }
     283
     284        // Remove old custom roles
     285        remove_role( 'bbp_moderator'   );
     286        remove_role( 'bbp_participant' );
     287
     288        // Remove bbPress 1.1 roles (BuddyPress)
     289        //remove_role( 'member'    );
     290        //remove_role( 'inactive'  );
     291        //remove_role( 'blocked'   );
     292        //remove_role( 'moderator' );
     293        //remove_role( 'keymaster' );
     294    }
     295}
  • branches/plugin/bbp-includes/bbp-user-functions.php

    r4141 r4164  
    13861386
    13871387    // Get the user's main role
    1388     $role = isset( $user->roles ) ? array_shift( $user->roles ) : bbp_get_anonymous_role();
     1388    $role = isset( $user->roles ) ? array_shift( $user->roles ) : '';
    13891389
    13901390    return apply_filters( 'bbp_get_user_role', $role, $user_id, $user );
  • branches/plugin/bbp-includes/bbp-user-template.php

    r4094 r4164  
    422422     * @param int $user_id
    423423     * @uses bbp_get_user_role() To get the main user role
    424      * @uses bbp_get_moderator_role() To get the moderator role
    425      * @uses bbp_get_participant_role() To get the participant role
    426      * @uses bbp_get_moderator_role() To get the moderator role
    427424     * @uses apply_filters() Calls 'bbp_get_user_display_role' with the
    428425     *                        display role, user id, and user role
     
    439436            $role = __( 'Key Master', 'bbpress' );
    440437
     438        // User is not registered
     439        } elseif ( empty( $user_id ) ) {
     440            $role = __( 'Guest', 'bbpress' );
     441
    441442        // Not the keymaster of Gozer
    442443        } else {
     
    444445            // Get the user's main role for display
    445446            switch ( $user_role ) {
    446 
    447                 /** bbPress Roles *********************************************/
    448 
    449                 // Anonymous
    450                 case bbp_get_anonymous_role() :
    451                     $role = __( 'Guest', 'bbpress' );
    452                     break;
    453 
    454                 // Multisite Participant Role
    455                 case bbp_get_participant_role() :
    456                     $role = __( 'Member', 'bbpress' );
    457                     break;
    458 
    459                 // Moderator
    460                 case bbp_get_moderator_role() :
    461                     $role = __( 'Moderator', 'bbpress' );
    462                     break;
    463 
    464                 /** WordPress Core Roles **************************************/
    465 
    466447                case 'administrator' :
    467448                case 'editor'        :
  • branches/plugin/bbp-theme-compat/bbpress/form-reply.php

    r4098 r4164  
    7979                    <?php endif; ?>
    8080                   
    81                     <?php if ( bbp_allow_topic_tags() ) : ?>
     81                    <?php if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags' ) ) : ?>
    8282
    8383                        <?php do_action( 'bbp_theme_before_reply_form_tags' ); ?>
  • branches/plugin/bbp-theme-compat/bbpress/form-topic.php

    r4098 r4164  
    105105                    <?php endif; ?>
    106106
    107                     <?php if ( bbp_allow_topic_tags() ) : ?>
     107                    <?php if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags' ) ) : ?>
    108108
    109109                        <?php do_action( 'bbp_theme_before_topic_form_tags' ); ?>
  • branches/plugin/bbp-themes/bbp-twentyten/bbpress/form-reply.php

    r4098 r4164  
    7979                    <?php endif; ?>
    8080
    81                     <?php if ( bbp_allow_topic_tags() ) : ?>
     81                    <?php if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags' ) ) : ?>
    8282
    8383                        <?php do_action( 'bbp_theme_before_reply_form_tags' ); ?>
  • branches/plugin/bbp-themes/bbp-twentyten/bbpress/form-topic.php

    r4098 r4164  
    105105                    <?php endif; ?>
    106106
    107                     <?php if ( bbp_allow_topic_tags() ) : ?>
     107                    <?php if ( bbp_allow_topic_tags() && current_user_can( 'assign_topic_tags' ) ) : ?>
    108108
    109109                        <?php do_action( 'bbp_theme_before_topic_form_tags' ); ?>
  • branches/plugin/bbpress.php

    r4154 r4164  
    174174        /** Versions **********************************************************/
    175175
    176         $this->version    = '2.2-bleeding'; // bbPress version
    177         $this->db_version = '211';          // bbPress DB version
     176        $this->version    = '2.1.2-r4146'; // bbPress version
     177        $this->db_version = '213';   // bbPress DB version
    178178
    179179        /** Paths *************************************************************/
Note: See TracChangeset for help on using the changeset viewer.