bbp_exclude_forum_ids( $type = 'string' )
Returns a meta_query that either includes or excludes hidden forum IDs from a query.
Description
Parameters
-
(Optional) The type of value to return. (string|array|meta_query)
Source
File: bp-forums/forums/functions.php
function bbp_exclude_forum_ids( $type = 'string' ) {
// Setup arrays
$private = $hidden = $meta_query = $forum_ids = array();
// Default return value
switch ( $type ) {
case 'string' :
$retval = '';
break;
case 'array' :
$retval = array();
break;
case 'meta_query' :
$retval = array( array() ) ;
break;
}
// Exclude for everyone but keymasters
if ( ! bbp_is_user_keymaster() ) {
// 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
$forum_ids = (array) array_filter( wp_parse_id_list( array_merge( $private, $hidden ) ) );
// There are forums that need to be excluded
if ( !empty( $forum_ids ) ) {
switch ( $type ) {
// Separate forum ID's into a comma separated string
case 'string' :
$retval = implode( ',', $forum_ids );
break;
// Use forum_ids array
case 'array' :
$retval = $forum_ids;
break;
// Build a meta_query
case 'meta_query' :
$retval = array(
'key' => '_bbp_forum_id',
'value' => implode( ',', $forum_ids ),
'type' => 'numeric',
'compare' => ( 1 < count( $forum_ids ) ) ? 'NOT IN' : '!='
);
break;
}
}
}
// Filter and return the results
return apply_filters( 'bbp_exclude_forum_ids', $retval, $forum_ids, $type );
}
Changelog
| Version | Description |
|---|---|
| bbPress (r3291) | 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.