Skip to:
Content

bbPress.org


Ignore:
Timestamp:
04/21/2011 08:35:23 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Improvements to forum visibility checking, template tags, and ensuring that template tag filters also pass the $forum_id for proper enhancement.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-forum-template.php

    r2998 r3008  
    7474        // Don't show private forums to normal users
    7575        if ( !current_user_can( 'read_private_forums' ) && empty( $r['meta_key'] ) && empty( $r['meta_value'] ) ) {
    76                 $r['meta_key']   = '_bbp_visibility';
    77                 $r['meta_value'] = 'public';
     76                $r['meta_query'] = array( array(
     77                        'key'     => '_bbp_visibility',
     78                        'value'   => 'public, private',
     79                        'compare' => 'IN'
     80                ) );
    7881        }
    7982
     
    11861189                $forum_id = bbp_get_forum_id( $forum_id );
    11871190
    1188                 return apply_filters( 'bbp_get_forum_status', get_post_meta( $forum_id, '_bbp_status', true ) );
     1191                return apply_filters( 'bbp_get_forum_status', get_post_meta( $forum_id, '_bbp_status', true ), $forum_id );
    11891192        }
    11901193
     
    12151218                $forum_id = bbp_get_forum_id( $forum_id );
    12161219
    1217                 return apply_filters( 'bbp_get_forum_visibility', get_post_meta( $forum_id, '_bbp_visibility', true ) );
     1220                return apply_filters( 'bbp_get_forum_visibility', get_post_meta( $forum_id, '_bbp_visibility', true ), $forum_id );
    12181221        }
    12191222
     
    12301233        $forum_id = bbp_get_forum_id( $forum_id );
    12311234        $type     = get_post_meta( $forum_id, '_bbp_forum_type', true );
    1232 
    1233         if ( !empty( $type ) && 'category' == $type )
    1234                 return true;
    1235 
    1236         return false;
     1235        $retval   = ( !empty( $type ) && 'category' == $type );
     1236
     1237        return apply_filters( 'bbp_is_forum_category', (bool) $retval, $forum_id );
    12371238}
    12381239
     
    12691270
    12701271                $forum_id = bbp_get_forum_id( $forum_id );
    1271 
    1272                 if ( $bbp->closed_status_id == bbp_get_forum_status( $forum_id ) )
    1273                         return true;
     1272                $retval    = ( $bbp->closed_status_id == bbp_get_forum_status( $forum_id ) );
    12741273
    12751274                if ( !empty( $check_ancestors ) ) {
     
    12771276
    12781277                        foreach ( (array) $ancestors as $ancestor ) {
    1279                                 if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) )
    1280                                         return true;
     1278                                if ( bbp_is_forum_category( $ancestor, false ) && bbp_is_forum_closed( $ancestor, false ) ) {
     1279                                        $retval = true;
     1280                                }
    12811281                        }
    12821282                }
    12831283
    1284                 return false;
     1284                return apply_filters( 'bbp_is_forum_closed', (bool) $retval, $forum_id, $check_ancestors );
    12851285        }
    12861286
     
    13061306
    13071307        // If post status is public, return true
    1308         $retval = ( 'public' == $visibility ) ? true : false;
     1308        $retval = ( 'public' == $visibility );
    13091309
    13101310        // Check ancestors and inherit their privacy setting for display
     
    13191319        }
    13201320
    1321         return apply_filters( 'bbp_is_forum_public', (bool) $retval );
     1321        return apply_filters( 'bbp_is_forum_public', (bool) $retval, $forum_id, $check_ancestors );
    13221322}
    13231323
     
    13431343
    13441344        // If post status is private, return true
    1345         $retval = ( 'private' == $visibility ) ? true : false;
     1345        $retval = ( 'private' == $visibility );
    13461346
    13471347        // Check ancestors and inherit their privacy setting for display
     
    13561356        }
    13571357
    1358         return apply_filters( 'bbp_is_forum_private', (bool) $retval );
     1358        return apply_filters( 'bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors );
    13591359}
    13601360
     
    13801380
    13811381        // If post status is private, return true
    1382         $retval = ( 'hidden' == $visibility ) ? true : false;
     1382        $retval = ( 'hidden' == $visibility );
    13831383
    13841384        // Check ancestors and inherit their privacy setting for display
     
    13931393        }
    13941394
    1395         return apply_filters( 'bbp_is_forum_hidden', (bool) $retval );
    1396 }
     1395        return apply_filters( 'bbp_is_forum_hidden', (bool) $retval, $forum_id, $check_ancestors );
     1396}
     1397
     1398function bbp_suppress_private_forum_meta( $retval, $forum_id ) {
     1399        if ( bbp_is_forum_private( $forum_id, false ) && !current_user_can( 'read_private_forums' ) )
     1400                return '-';
     1401
     1402        return $retval;
     1403}
     1404add_filter( 'bbp_get_forum_topic_count',    'bbp_suppress_private_forum_meta', 10, 2 );
     1405add_filter( 'bbp_get_forum_reply_count',    'bbp_suppress_private_forum_meta', 10, 2 );
     1406add_filter( 'bbp_get_forum_post_count',     'bbp_suppress_private_forum_meta', 10, 2 );
     1407add_filter( 'bbp_get_forum_freshness_link', 'bbp_suppress_private_forum_meta', 10, 2 );
     1408
     1409function bbp_suppress_private_author_link( $author_link, $args ) {
     1410        if ( empty( $args['post_id'] ) || current_user_can( 'read_private_forums' ) )
     1411                return $author_link;
     1412
     1413        $post_type = get_post_field( 'post_type', $args['post_id'] );
     1414
     1415        switch ( $post_type ) {
     1416                case bbp_get_topic_post_type() :
     1417                        if ( bbp_is_forum_private( bbp_get_topic_forum_id( $args['post_id'] ) ) )
     1418                                return '';
     1419
     1420                        break;
     1421
     1422                case bbp_get_reply_post_type() :
     1423                        if ( bbp_is_forum_private( bbp_get_reply_forum_id( $args['post_id'] ) ) )
     1424                                return '';
     1425
     1426                        break;
     1427
     1428                default :
     1429                        if ( bbp_is_forum_private( $args['post_id'] ) )
     1430                                return '';
     1431
     1432                        break;
     1433        }
     1434
     1435        return $author_link;
     1436}
     1437add_filter( 'bbp_get_author_link',       'bbp_suppress_private_author_link', 10, 2 );
     1438add_filter( 'bbp_get_topic_author_link', 'bbp_suppress_private_author_link', 10, 2 );
     1439add_filter( 'bbp_get_reply_author_link', 'bbp_suppress_private_author_link', 10, 2 );
    13971440
    13981441/**
Note: See TracChangeset for help on using the changeset viewer.