Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/20/2017 10:44:00 AM (8 years ago)
Author:
johnjamesjacoby
Message:

Moderation: Allow per-forum moderators to edit topics & replies inside of forums they have moderation control over.

This feature require the following changes:

  • Prefer read_forum capability check over read_private_forums or read_hidden_forums, and include a $forum_id parameter to assist map_meta_cap filters
  • Prefer edit_others_topics|replies over moderate where appropriate, to ensure capability mappings work as intended
  • Introduce bbp_get_public_topic_statuses() to replace several duplicate occurrences of the same array usage (also allow these to be filtered)
  • Introduce bbp_is_topic_public() (not to be confused with bbp_is_topic_published()) to provide parity with bbp_is_forum_public() and also utilize bbp_get_public_topic_statuses() from above
  • Add local caching to bbp_exclude_forum_ids() as a performance optimization to reduce the depth of current_user_can() calls when private & hidden forums are in use
  • Add user_can( 'moderate' ) capability checks to various mappings, to ensure forum moderators can read/edit/delete content inside of the individual forums they are moderators of
  • Use bbp_get_user_id() where appropriate, rather than casting as int
  • Various surrounding code clean-ups

See #2593.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/replies/functions.php

    r6369 r6384  
    179179
    180180        // User cannot create replies
    181         if ( !current_user_can( 'publish_replies' ) ) {
     181        if ( ! current_user_can( 'publish_replies' ) ) {
    182182            bbp_add_error( 'bbp_reply_permission', __( '<strong>ERROR</strong>: You do not have permission to reply.', 'bbpress' ) );
    183183        }
     
    271271
    272272            // Forum is closed and user cannot access
    273             if ( bbp_is_forum_closed( $forum_id ) && !current_user_can( 'edit_forum', $forum_id ) ) {
     273            if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) {
    274274                bbp_add_error( 'bbp_new_reply_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new replies.', 'bbpress' ) );
    275275            }
    276276
    277277            // Forum is private and user cannot access
    278             if ( bbp_is_forum_private( $forum_id ) ) {
    279                 if ( !current_user_can( 'read_private_forums' ) ) {
    280                     bbp_add_error( 'bbp_new_reply_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
    281                 }
     278            if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) {
     279                bbp_add_error( 'bbp_new_reply_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
    282280
    283281            // Forum is hidden and user cannot access
    284             } elseif ( bbp_is_forum_hidden( $forum_id ) ) {
    285                 if ( !current_user_can( 'read_hidden_forums' ) ) {
    286                     bbp_add_error( 'bbp_new_reply_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
    287                 }
     282            } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) {
     283                bbp_add_error( 'bbp_new_reply_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
    288284            }
    289285        }
     
    572568
    573569            // User cannot edit this reply
    574             if ( !current_user_can( 'edit_reply', $reply_id ) ) {
     570            if ( ! current_user_can( 'edit_reply', $reply_id ) ) {
    575571                bbp_add_error( 'bbp_edit_reply_permission', __( '<strong>ERROR</strong>: You do not have permission to edit that reply.', 'bbpress' ) );
    576572                return;
     
    614610
    615611            // Forum is closed and user cannot access
    616             if ( bbp_is_forum_closed( $forum_id ) && !current_user_can( 'edit_forum', $forum_id ) ) {
     612            if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) {
    617613                bbp_add_error( 'bbp_edit_reply_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new replies.', 'bbpress' ) );
    618614            }
    619615
    620616            // Forum is private and user cannot access
    621             if ( bbp_is_forum_private( $forum_id ) ) {
    622                 if ( !current_user_can( 'read_private_forums' ) ) {
    623                     bbp_add_error( 'bbp_edit_reply_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
    624                 }
     617            if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) {
     618                bbp_add_error( 'bbp_edit_reply_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
    625619
    626620            // Forum is hidden and user cannot access
    627             } elseif ( bbp_is_forum_hidden( $forum_id ) ) {
    628                 if ( !current_user_can( 'read_hidden_forums' ) ) {
    629                     bbp_add_error( 'bbp_edit_reply_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
    630                 }
     621            } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) {
     622                bbp_add_error( 'bbp_edit_reply_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) );
    631623            }
    632624        }
     
    889881
    890882    } else {
    891         if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) {
     883        if ( empty( $is_edit ) && ! current_user_can( 'throttle' ) ) {
    892884            bbp_update_user_last_posted( $author_id );
    893885        }
     
    13621354
    13631355    // Use cannot edit topic
    1364     if ( !current_user_can( 'edit_topic', $source_topic->ID ) ) {
     1356    if ( ! current_user_can( 'edit_topic', $source_topic->ID ) ) {
    13651357        bbp_add_error( 'bbp_move_reply_source_permission', __( '<strong>ERROR</strong>: You do not have permission to edit the source topic.', 'bbpress' ) );
    13661358    }
     
    14001392
    14011393                // User cannot edit the destination topic
    1402                 if ( !current_user_can( 'edit_topic', $destination_topic->ID ) ) {
     1394                if ( ! current_user_can( 'edit_topic', $destination_topic->ID ) ) {
    14031395                    bbp_add_error( 'bbp_move_reply_destination_permission', __( '<strong>ERROR</strong>: You do not have permission to edit the destination topic.', 'bbpress' ) );
    14041396                }
Note: See TracChangeset for help on using the changeset viewer.