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

    r6357 r6384  
    694694    // Use passed integer as post_parent
    695695    if ( is_numeric( $args ) ) {
    696         $args = array( 'post_parent' => $args );
     696        $args = array( 'post_parent' => bbp_get_forum_id( $args ) );
    697697    }
    698698
     
    729729        'no_found_rows'       => true
    730730    ), 'forum_get_subforums' );
     731
     732    // Ensure post_parent is properly set
    731733    $r['post_parent'] = bbp_get_forum_id( $r['post_parent'] );
    732734
     
    735737
    736738    // No forum passed
    737     $sub_forums = ! empty( $r['post_parent'] ) ? $get_posts->query( $r ) : array();
     739    $sub_forums = ! empty( $r['post_parent'] )
     740        ? $get_posts->query( $r )
     741        : array();
    738742
    739743    return (array) apply_filters( 'bbp_forum_get_subforums', $sub_forums, $r, $args );
     
    13011305
    13021306            // Hidden link
    1303             $retval .= ! bbp_get_view_all()
     1307            $retval .= ! bbp_get_view_all( 'edit_others_topics' )
    13041308                ? " <a href='" . esc_url( bbp_add_view_all( $link, true ) ) . "'>" . esc_html( $extra ) . "</a>"
    13051309                : " {$extra}";
     
    19441948 */
    19451949function bbp_suppress_private_forum_meta( $retval, $forum_id ) {
    1946     if ( bbp_is_forum_private( $forum_id, false ) && ! current_user_can( 'read_private_forums' ) ) {
     1950    if ( bbp_is_forum_private( $forum_id, false ) && ! current_user_can( 'read_forum', $forum_id ) ) {
    19471951        $retval = '-';
    19481952    }
     
    19781982
    19791983        // What post type are we looking at?
    1980         $post_type = get_post_field( 'post_type', $args['post_id'] );
    1981 
    1982         switch ( $post_type ) {
     1984        switch ( get_post_type( $args['post_id'] ) ) {
    19831985
    19841986            // Topic
    19851987            case bbp_get_topic_post_type() :
    1986                 if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) ) {
    1987                     $retval = '';
    1988                 }
    1989 
     1988                $forum_id = bbp_get_topic_forum_id( $args['post_id'] );
    19901989                break;
    19911990
    19921991            // Reply
    19931992            case bbp_get_reply_post_type() :
    1994                 if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) ) {
    1995                     $retval = '';
    1996                 }
    1997 
     1993                $forum_id = bbp_get_reply_forum_id( $args['post_id'] );
    19981994                break;
    19991995
    20001996            // Post
    20011997            default :
    2002                 if ( bbp_is_forum_private( $args['post_id'] ) ) {
    2003                     $retval = '';
    2004                 }
    2005 
     1998                $forum_id = bbp_get_forum_id( $args['post_id'] );
    20061999                break;
    20072000        }
    2008     }
    2009 
    2010     return apply_filters( 'bbp_suppress_private_author_link', $retval );
     2001
     2002        // Hide if forum is private
     2003        if ( bbp_is_forum_private( $forum_id ) ) {
     2004            $retval = '';
     2005        }
     2006    }
     2007
     2008    return apply_filters( 'bbp_suppress_private_author_link', $retval, $author_link, $args );
    20112009}
    20122010
Note: See TracChangeset for help on using the changeset viewer.