bbp_get_forums_for_current_user( type $args = array() )
Get the forums the current user has the ability to see and post to
Description
Parameters
- $args
-
(Optional)
Default value: array()
Return
(type)
Source
File: bp-forums/users/template.php
function bbp_get_forums_for_current_user( $args = array() ) {
// Setup arrays
$private = $hidden = $post__not_in = array();
// Private forums
if ( !current_user_can( 'read_private_forums' ) )
$private = bbp_get_private_forum_ids();
// Hidden forums
if ( !current_user_can( 'read_hidden_forums' ) )
$hidden = bbp_get_hidden_forum_ids();
// Merge private and hidden forums together and remove any empties
$forum_ids = (array) array_filter( wp_parse_id_list( array_merge( $private, $hidden ) ) );
// There are forums that need to be ex
if ( !empty( $forum_ids ) )
$post__not_in = implode( ',', $forum_ids );
// Parse arguments against default values
$r = bbp_parse_args( $args, array(
'post_type' => bbp_get_forum_post_type(),
'post_status' => bbp_get_public_status_id(),
'numberposts' => -1,
'exclude' => $post__not_in
), 'get_forums_for_current_user' );
// Get the forums
$forums = get_posts( $r );
// No availabe forums
if ( empty( $forums ) )
$forums = false;
return apply_filters( 'bbp_get_forums_for_current_user', $forums );
}
Changelog
| Version | Description |
|---|---|
| bbPress (r3127) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.