groups->table_name . ' AS g LEFT JOIN ' . $bp->groups->table_name_groupmeta . ' AS gm ON g.id = gm.group_id '; return $sql; } function groups_add_forum_where_sql( $sql = '' ) { global $bp; // Define locale variable $parts = array(); // Set this for groups $parts['groups'] = "(gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id)"; // Restrict to public... $parts['private'] = "g.status = 'public'"; /** * ...but do some checks to possibly remove public restriction. * * Decide if private are visible */ // Are we in our own profile? if ( bp_is_my_profile() ) unset( $parts['private'] ); // Are we a super admin? elseif ( bp_current_user_can( 'bp_moderate' ) ) unset( $parts['private'] ); // No need to filter on a single item elseif ( bp_is_single_item() ) unset( $parts['private'] ); // Check the SQL filter that was passed if ( !empty( $sql ) ) $parts['passed'] = $sql; // Assemble Voltron $parts_string = implode( ' AND ', $parts ); // Set it to the global filter $bp->groups->filter_sql = $parts_string; // Return the global filter return $bp->groups->filter_sql; } function groups_filter_bbpress_caps( $value, $cap, $args ) { global $bp; if ( bp_current_user_can( 'bp_moderate' ) ) return true; if ( 'add_tag_to' == $cap ) if ( $bp->groups->current_group->user_has_access ) return true; if ( 'manage_forums' == $cap && is_user_logged_in() ) return true; return $value; } add_filter( 'bb_current_user_can', 'groups_filter_bbpress_caps', 10, 3 ); /** * Amends the forum directory's "last active" bbPress SQL query to stop it fetching * information we aren't going to use. This speeds up the query. * * @see BB_Query::_filter_sql() * @since BuddyPress (1.5) */ function groups_filter_forums_root_page_sql( $sql ) { return apply_filters( 'groups_filter_bbpress_root_page_sql', 't.topic_id' ); } add_filter( 'get_latest_topics_fields', 'groups_filter_forums_root_page_sql' );