Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/26/2011 10:40:54 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Consolidate topic form access checks.

File:
1 edited

Legend:

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

    r3221 r3236  
    11631163        if ( bbp_is_forum() ) {
    11641164
    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;
     1165                // Forum is open
     1166                if ( bbp_is_forum_open() ) {
     1167
     1168                        // What is the visibility of this forum
     1169                        switch ( bbp_get_forum_visibility() ) {
     1170
     1171                                // Public
     1172                                case 'publish' :
     1173
     1174                                        // User cannot publish topics
     1175                                        if ( current_user_can( 'publish_topics' ) )
     1176                                                $retval = true;
     1177
     1178                                        // Anonymous posting is allowed
     1179                                        if ( bbp_allow_anonymous() && !is_user_logged_in() )
     1180                                                $retval = true;
     1181
     1182                                        break;
     1183
     1184                                // Private forums
     1185                                case 'private' :
     1186                                        if ( current_user_can( 'read_private_forums' ) )
     1187                                                $retval = true;
     1188
     1189                                        break;
     1190
     1191                                // Hidden forums
     1192                                case 'hidden'  :
     1193                                        if ( current_user_can( 'read_hidden_forums' ) )
     1194                                                $retval = true;
     1195
     1196                                        break;
     1197                        }
    11941198                }
    11951199
    … …  
    12151219}
    12161220
    1217 /**
    1218  * Performs a series of checks to ensure the current user can create topics in
    1219  * this specific forum or scope.
    1220  *
    1221  * @since bbPress (r3127)
    1222  *
    1223  * @uses bbp_is_forum_category()
    1224  * @uses bbp_is_forum_closed()
    1225  * @uses current_user_can()
    1226  * @uses bbp_get_topic_forum_id()
    1227  * @uses bbp_is_topic_edit()
    1228  *
    1229  * @return bool
    1230  */
    1231 function bbp_current_user_can_create_topic_in_forum() {
    1232 
    1233         // Always allow super admins
    1234         if ( is_super_admin() )
    1235                 return true;
    1236 
    1237         // Users need to earn access
    1238         $retval = false;
    1239 
    1240         // Looking at a single forum
    1241         if ( bbp_is_forum() ) {
    1242 
    1243                 // Forum is not a category
    1244                 if ( !bbp_is_forum_category() ) {
    1245 
    1246                         // Forum is open
    1247                         $retval = (bool) bbp_is_forum_open();
    1248                 }
    1249 
    1250         // Editing a single topic
    1251         } elseif ( bbp_is_topic_edit() ) {
    1252 
    1253                 // If you can edit this forum, you can edit topics in this forum
    1254                 if ( current_user_can( 'edit_forum', bbp_get_topic_forum_id() ) )
    1255                         $retval = true;
    1256 
    1257         // Fallback for shortcodes
    1258         } elseif ( is_page() || is_single() ) {
    1259 
    1260                 // Page or single post, and user can publish topics or anonymous
    1261                 // posting is allowed.
    1262                 if ( current_user_can( 'publish_topics' ) || ( !is_user_logged_in() && bbp_allow_anonymous() ) )
    1263                         $retval = true;
    1264 
    1265         }
    1266 
    1267         // Allow access to be filtered
    1268         return apply_filters( 'bbp_current_user_can_create_topic_in_forum', $retval );
    1269 }
    1270 
    1271 
    12721221?>
Note: See TracChangeset for help on using the changeset viewer.