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/template.php

    r6362 r6384  
    173173
    174174    // What are the default allowed statuses (based on user caps)
    175     if ( bbp_get_view_all() ) {
     175    if ( bbp_get_view_all( 'edit_others_topics' ) ) {
    176176
    177177        // Default view=all statuses
     
    310310
    311311                // What are the default allowed statuses (based on user caps)
    312                 if ( bbp_get_view_all() ) {
     312                if ( bbp_get_view_all( 'edit_others_topics' ) ) {
    313313                    $sticky_query['post_status'] = $r['post_status'];
    314314
     
    900900        }
    901901
     902        // Maybe add view-all args
     903        $add_args = bbp_get_view_all( 'edit_others_replies' )
     904            ? array( 'view' => 'all' )
     905            : false;
     906
    902907        // Add pagination to query object
    903908        $pagination_links = paginate_links( array(
     
    909914            'mid_size'  => 2,
    910915            'end_size'  => 3,
    911             'add_args'  => ( bbp_get_view_all() ) ? array( 'view' => 'all' ) : false
     916            'add_args'  => $add_args
    912917        ) );
    913918
     
    11631168
    11641169/**
     1170 * Return array of public topic statuses.
     1171 *
     1172 * @since 2.6.0 bbPress (r6383)
     1173 *
     1174 * @uses bbp_get_public_status_id()
     1175 * @uses bbp_get_closed_status_id()
     1176 *
     1177 * @return array
     1178 */
     1179function bbp_get_public_topic_statuses() {
     1180    $statuses = bbp_get_public_topic_statuses();
     1181
     1182    return (array) apply_filters( 'bbp_get_public_topic_statuses', $statuses );
     1183}
     1184
     1185/**
    11651186 * Is the topic closed to new replies?
    11661187 *
     
    11971218
    11981219/**
    1199  * Is the topic not spam or deleted?
     1220 * Is the topic publicly viewable?
     1221 *
     1222 * @since 2.6.0 bbPress (r6383)
     1223 *
     1224 * @param int $topic_id Optional. Topic id
     1225 * @uses bbp_get_topic_id() To get the topic id
     1226 * @uses bbp_get_topic_status() To get the topic status
     1227 * @uses apply_filters() Calls 'bbp_is_topic_public' with the topic id
     1228 * @return bool True if public, false if not.
     1229 */
     1230function bbp_is_topic_public( $topic_id = 0 ) {
     1231    $topic_id  = bbp_get_topic_id( $topic_id );
     1232    $status    = bbp_get_topic_status( $topic_id );
     1233    $public    = bbp_get_public_topic_statuses();
     1234    $is_public = in_array( $status, $public, true );
     1235
     1236    return (bool) apply_filters( 'bbp_is_topic_public', (bool) $is_public, $topic_id );
     1237}
     1238
     1239/**
     1240 * Does the topic have a published status?
    12001241 *
    12011242 * @since 2.0.0 bbPress (r3496)
     
    22412282
    22422283            // Hidden link
    2243             $retval .= ! bbp_get_view_all()
     2284            $retval .= ! bbp_get_view_all( 'edit_others_replies' )
    22442285                ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . "</a>"
    22452286                : " {$extra}";
Note: See TracChangeset for help on using the changeset viewer.