Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/20/2017 10:44:00 AM (5 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/topics/functions.php

    r6341 r6384  
    260260
    261261            // Forum is private and user cannot access
    262             if ( bbp_is_forum_private( $forum_id ) ) {
    263                 if ( ! current_user_can( 'read_private_forums' ) ) {
    264                     bbp_add_error( 'bbp_new_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
    265                 }
     262            if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) {
     263                bbp_add_error( 'bbp_new_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
    266264
    267265            // Forum is hidden and user cannot access
    268             } elseif ( bbp_is_forum_hidden( $forum_id ) ) {
    269                 if ( ! current_user_can( 'read_hidden_forums' ) ) {
    270                     bbp_add_error( 'bbp_new_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
    271                 }
     266            } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) {
     267                bbp_add_error( 'bbp_new_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
    272268            }
    273269        }
     
    562558
    563559            // Forum is private and user cannot access
    564             if ( bbp_is_forum_private( $forum_id ) ) {
    565                 if ( ! current_user_can( 'read_private_forums' ) ) {
    566                     bbp_add_error( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
    567                 }
     560            if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) {
     561                bbp_add_error( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
    568562
    569563            // Forum is hidden and user cannot access
    570             } elseif ( bbp_is_forum_hidden( $forum_id ) ) {
    571                 if ( ! current_user_can( 'read_hidden_forums' ) ) {
    572                     bbp_add_error( 'bbp_edit_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
    573                 }
     564            } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) {
     565                bbp_add_error( 'bbp_edit_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
    574566            }
    575567        }
     
    619611
    620612        // Set post status to pending if public or closed
    621         if ( in_array( $topic->post_status, array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ) ) {
     613        if ( bbp_is_topic_public( $topic->ID ) ) {
    622614            $topic_status = bbp_get_pending_status_id();
    623615        }
     
    746738
    747739        // View all?
    748         $view_all = bbp_get_view_all();
     740        $view_all = bbp_get_view_all( 'edit_others_replies' );
    749741
    750742        // Get the topic URL
Note: See TracChangeset for help on using the changeset viewer.