Skip to:
Content

bbPress.org

Changeset 3159


Ignore:
Timestamp:
05/15/2011 07:12:15 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Flesh out current-user topic-form access functions with more appropriate hierarchy of checks. Fix #1516.

File:
1 edited

Legend:

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

    r3127 r3159  
    11021102function bbp_get_forums_for_current_user( $args = array() ) {
    11031103
     1104    // Setup arrays
     1105    $private = $hidden = $post__not_in = array();
     1106
     1107    // Private forums
     1108    if ( !current_user_can( 'read_private_forums' ) )
     1109        $private = bbp_get_private_forum_ids();
     1110
     1111    // Hidden forums
     1112    if ( !current_user_can( 'read_hidden_forums' ) )
     1113        $hidden  = bbp_get_hidden_forum_ids();
     1114
     1115    // Merge private and hidden forums together
     1116    $forum_ids = array_merge( $private, $hidden );
     1117
     1118    // There are forums that need to be ex
     1119    if ( !empty( $forum_ids ) )
     1120        $post__not_in = implode( ',', $forum_ids );
     1121
    11041122    $defaults = array(
    11051123        'post_type'   => bbp_get_forum_post_type(),
    1106         'child_of'    => '0',
     1124        'post_status' => 'publish',
    11071125        'numberposts' => -1,
    1108         'post_status' => 'publish',
     1126        'exclude'     => $post__not_in
    11091127    );
    11101128    $r = wp_parse_args( $args, $defaults );
    11111129
    1112     // Exclude forums the user cannot post to
    1113     $r = bbp_exclude_forum_ids( $r );
    1114 
    11151130    // Get the forums
    1116     if ( ! ( $posts = get_posts( $r ) ) )
    1117         $posts = false;
    1118 
    1119     return apply_filters( 'bbp_get_forums_for_current_user', $posts );
     1131    $forums = get_posts( $r );
     1132
     1133    // No availabe forums
     1134    if ( empty( $forums ) )
     1135        $forums = false;
     1136
     1137    return apply_filters( 'bbp_get_forums_for_current_user', $forums );
    11201138}
    11211139
     
    11251143 * @since bbPress (r3127)
    11261144 *
    1127  * @uses bbp_get_forums_for_current_user()
    11281145 * @uses bbp_is_topic_edit()
    11291146 * @uses current_user_can()
     
    11351152 */
    11361153function bbp_current_user_can_access_create_topic_form() {
    1137     if ( bbp_get_forums_for_current_user() && ( ( bbp_is_topic_edit() && current_user_can( 'edit_topic', bbp_get_topic_id() ) ) || current_user_can( 'publish_topics' ) || ( bbp_allow_anonymous() && !is_user_logged_in() ) ) )
     1154
     1155    // Always allow super admins
     1156    if ( is_super_admin() )
    11381157        return true;
    11391158
    1140     return false;
     1159    // Users need to earn access
     1160    $retval = false;
     1161
     1162    // Looking at a single forum
     1163    if ( bbp_is_forum() ) {
     1164
     1165        // What is the visibility of this forum
     1166        switch ( bbp_get_forum_visibility() ) {
     1167
     1168            // Public
     1169            case 'publish' :
     1170
     1171                // User cannot publish topics
     1172                if ( current_user_can( 'publish_topics' ) )
     1173                    $retval = true;
     1174
     1175                // Anonymous posting is allowed
     1176                if ( bbp_allow_anonymous() && !is_user_logged_in() )
     1177                    $retval = true;
     1178
     1179                break;
     1180
     1181            // Private forums
     1182            case 'private' :
     1183                if ( current_user_can( 'read_private_forums' ) )
     1184                    $retval = true;
     1185
     1186                break;
     1187
     1188            // Hidden forums
     1189            case 'hidden'  :
     1190                if ( current_user_can( 'read_hidden_forums' ) )
     1191                    $retval = true;
     1192
     1193                break;
     1194        }
     1195
     1196    // Editing a single topic
     1197    } elseif ( bbp_is_topic_edit() ) {
     1198
     1199        // User can edit edit this topic
     1200        if ( current_user_can( 'edit_topic', bbp_get_topic_id() ) )
     1201            $retval = true;
     1202    }
     1203
     1204    // Allow access to be filtered
     1205    return apply_filters( 'bbp_current_user_can_access_create_topic_form', $retval );
    11411206}
    11421207
     
    11561221 */
    11571222function bbp_current_user_can_create_topic_in_forum() {
    1158     if ( ( !bbp_is_forum_category() && ( !bbp_is_forum_closed() || current_user_can( 'edit_forum', bbp_get_topic_forum_id() ) ) ) || bbp_is_topic_edit() )
     1223
     1224    // Always allow super admins
     1225    if ( is_super_admin() )
    11591226        return true;
    11601227
    1161     return false;
     1228    // Users need to earn access
     1229    $retval = false;
     1230
     1231    // Looking at a single forum
     1232    if ( bbp_is_forum() ) {
     1233
     1234        // Forum is not a category
     1235        if ( !bbp_is_forum_category() ) {
     1236
     1237            // Forum is open
     1238            $retval = (bool) bbp_is_forum_open();
     1239        }
     1240
     1241    // Editing a single topic
     1242    } elseif ( bbp_is_topic_edit() ) {
     1243
     1244        // If you can edit this forum, you can edit topics in this forum
     1245        if ( current_user_can( 'edit_forum', bbp_get_topic_forum_id() ) )
     1246            $retval = true;
     1247    }
     1248
     1249    // Allow access to be filtered
     1250    return apply_filters( 'bbp_current_user_can_create_topic_in_forum', $retval );
    11621251}
    11631252
Note: See TracChangeset for help on using the changeset viewer.