Skip to:
Content

bbPress.org

Changeset 6425


Ignore:
Timestamp:
05/26/2017 09:14:15 PM (4 years ago)
Author:
johnjamesjacoby
Message:

Users: Introduce bbp_allow_forums_of_user().

This filter-only function will be used to remove private & hidden forums from being excluded in queries, for users who are explicitly allowed forums that they would not otherwise be able to access.

See #2593.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/forums/capabilities.php

    r6407 r6425  
    258258    return (bool) apply_filters( 'bbp_is_user_forum_moderator', $retval, $user_id, $forum_id );
    259259}
     260
     261/**
     262 * Filter an array of forum IDs that are being excluded, and remove any forum
     263 * IDs a user explicitly has access to.
     264 *
     265 * This typically means private or hidden forums the user has moderation rights
     266 * to, but it can be filtered to mean just about anything.
     267 *
     268 * This function filters the return values of the following functions:
     269 * - `bbp_get_private_forum_ids()`
     270 * - `bbp_get_hidden_forum_ids()`
     271 *
     272 * @since 2.6.0 bbPress (r6422)
     273 *
     274 * @param array $forum_ids Forum IDs to check if the user ID is a moderator of
     275 * @param int   $user_id   User ID to check if is a moderator of forums
     276 *
     277 * @return array
     278 */
     279function bbp_allow_forums_of_user( $forum_ids = array(), $user_id = 0 ) {
     280
     281    // Store the original forum IDs
     282    $original_forum_ids = $forum_ids;
     283
     284    // Per-forum Moderators
     285    if ( bbp_allow_forum_mods() ) {
     286
     287        // Loop through forum IDs
     288        foreach ( $forum_ids as $key => $forum_id ) {
     289
     290            // Unset forum ID if user is a moderator
     291            if ( bbp_is_user_forum_moderator( $user_id, $forum_id ) ) {
     292                unset( $forum_ids[ $key ] );
     293            }
     294        }
     295    }
     296
     297    // Filter & return
     298    return (array) apply_filters( 'bbp_allow_forums_of_user', $forum_ids, $user_id, $original_forum_ids );
     299}
Note: See TracChangeset for help on using the changeset viewer.