Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/15/2015 03:59:23 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Moderators: First pass at per-forum moderators.

This commit introduces a powerful feature commonly found in other popular forum software that has been on our wishlist for nearly 9 years. It includes the following changes:

  • Custom forum-mod taxonomy for assigning user nicenames to forum IDs
  • Associated functions for defining capabilities, labels, etc...
  • New capability filters for ensuring forum moderators have the ability to moderate forums even without the moderator role assignment
  • New option for toggling the entire feature on/off (on by default)

Props jmdodd, netweb. See #459.

File:
1 edited

Legend:

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

    r5827 r5834  
    1515 * @since bbPress (r4242)
    1616 *
    17  * @param array $caps Capabilities for meta capability
    18  * @param string $cap Capability name
    19  * @param int $user_id User id
    20  * @param array $args Arguments
     17 * @param array  $caps Capabilities for meta capability.
     18 * @param string $cap Capability name.
     19 * @param int    $user_id User id.
     20 * @param array  $args Arguments.
     21 * @uses bbp_is_user_inactive() To check if user is spammer or deleted
     22 * @uses get_post() To get the post
     23 * @uses bbp_get_forum_post_type() To get the forum post type
     24 * @uses bbp_get_topic_post_type() To get the topic post type
     25 * @uses bbp_get_topic_forum_id() To get the topic forum id
     26 * @uses bbp_get_reply_post_type() To get the reply post type
     27 * @uses bbp_get_reply_forum_id() To get the reply forum id
     28 * @uses bbp_is_user_forum_mod() To check if the user is a forum moderator
    2129 * @uses apply_filters() Filter mapped results
     30 *
    2231 * @return array Actual capabilities for meta capability
    2332 */
     
    2635    // What capability is being checked?
    2736    switch ( $cap ) {
    28         case 'spectate'    :
    29         case 'participate' :
    30         case 'moderate'    :
    31 
    32             // Do not allow inactive users
     37        case 'spectate' :
     38
     39            // Do not allow inactive users.
    3340            if ( bbp_is_user_inactive( $user_id ) ) {
    3441                $caps = array( 'do_not_allow' );
    3542
    36             // Moderators are always participants
     43            // Default to the current cap.
    3744            } else {
    3845                $caps = array( $cap );
     46            }
     47            break;
     48
     49        case 'participate' :
     50
     51            // Do not allow inactive users.
     52            if ( bbp_is_user_inactive( $user_id ) ) {
     53                $caps = array( 'do_not_allow' );
     54
     55            // Default to the current cap.
     56            } else {
     57                $caps = array( $cap );
     58            }
     59            break;
     60
     61        case 'moderate' :
     62
     63            // Do not allow inactive users.
     64            if ( bbp_is_user_inactive( $user_id ) ) {
     65                $caps = array( 'do_not_allow' );
     66
     67            // Default to the current cap.
     68            } else {
     69                $caps = array( $cap );
     70
     71                // Bail if no post to check.
     72                if ( empty( $args[0] ) ) {
     73                    break;
     74                }
     75
     76                // Get the post.
     77                $_post = get_post( $args[0] );
     78                if ( empty( $_post ) ) {
     79                    break;
     80                }
     81
     82                // Get forum ID for specific type of post.
     83                switch ( $_post->post_type ) {
     84
     85                    // Forum.
     86                    case bbp_get_forum_post_type() :
     87                        $forum_id = $_post->ID;
     88                        break;
     89
     90                    // Topic.
     91                    case bbp_get_topic_post_type() :
     92                        $forum_id = bbp_get_topic_forum_id( $_post->ID );
     93                        break;
     94
     95                    // Reply.
     96                    case bbp_get_reply_post_type() :
     97                        $forum_id = bbp_get_reply_forum_id( $_post->ID );
     98                        break;
     99
     100                    // Any other post type defaults to 0.
     101                    default :
     102                        $forum_id = 0;
     103                        break;
     104                }
     105
     106                // Bail if no forum ID.
     107                if ( empty( $forum_id ) ) {
     108                    break;
     109                }
     110
     111                // If user is a per-forum moderator, make sure they can spectate.
     112                if ( bbp_is_user_forum_mod( $user_id, $forum_id ) ) {
     113                    $caps = array( 'spectate' );
     114                }
    39115            }
    40116
     
    212288        return;
    213289    }
    214    
     290
    215291    // Bail if current user cannot promote the passing user
    216292    if ( ! current_user_can( 'promote_user', $user_id ) ) {
     
    308384
    309385    // Don't add the user, but still give them the correct caps dynamically
    310     } else {       
     386    } else {
    311387        $bbp->current_user->caps[$new_role] = true;
    312388        $bbp->current_user->get_role_caps();
     
    671747 * @since bbPress (r4783)
    672748 *
    673  * @param int $user_id 
     749 * @param int $user_id
    674750 * @return bool True if keymaster, false if not
    675751 */
Note: See TracChangeset for help on using the changeset viewer.