/** * Returns a meta_query that either includes or excludes hidden forum IDs * from a query. * * @since bbPress (r3291) * * @param string Optional. The type of value to return. (string|array|meta_query) * * @uses bbp_is_user_keymaster() * @uses bbp_get_hidden_forum_ids() * @uses bbp_get_private_forum_ids() * @uses apply_filters() */ 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 // Use forum_ids array case 'array': $retval = $forum_ids; break; // Build a meta_query // 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); }
/** * Get the forums the current user has the ability to see and post to * * @since 2.0.0 bbPress (r3127) * * @uses bbp_get_forum_post_type() * @uses get_posts() * * @param type $args * @return type */ function bbp_get_forums_for_current_user($args = array()) { // Setup arrays $private = $hidden = $exclude = 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 excluded if (!empty($forum_ids)) { $exclude = 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' => $exclude), '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); }