groups->table_name . ' AS g LEFT JOIN ' . $bp->groups->table_name_groupmeta . ' AS gm ON g.id = gm.group_id '; return $sql; } /** * Add WHERE clauses to bbPress query for group-specific data and access protection. * * @since 1.1.0 * * @param string $sql SQL Statement to amend. * @return string */ function groups_add_forum_where_sql( $sql = '' ) { // 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 ); $bp = buddypress(); // Set it to the global filter. $bp->groups->filter_sql = $parts_string; // Return the global filter. return $bp->groups->filter_sql; } /** * Modify bbPress caps for bp-forums. * * @since 1.1.0 * * @param bool $value Original value for current_user_can check. * @param string $cap Capability checked. * @param array $args Arguments for the caps. * @return bool */ function groups_filter_bbpress_caps( $value, $cap, $args ) { if ( bp_current_user_can( 'bp_moderate' ) ) return true; if ( 'add_tag_to' === $cap ) { $bp = buddypress(); 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. * * @since 1.5.0 * * @see BB_Query::_filter_sql() * * @param string $sql SQL statement. * @return string */ function groups_filter_forums_root_page_sql( $sql ) { /** * Filters the forum directory's "last active" bbPress SQL query. * * This filter is used to prevent fetching information that is not used. * * @since 1.5.0 * * @param string $value SQL string to specify fetching just topic_id. */ return apply_filters( 'groups_filter_bbpress_root_page_sql', 't.topic_id' ); } add_filter( 'get_latest_topics_fields', 'groups_filter_forums_root_page_sql' ); /** * Should BuddyPress load the mentions scripts and related assets, including results to prime the * mentions suggestions? * * @since 2.2.0 * * @param bool $load_mentions True to load mentions assets, false otherwise. * @param bool $mentions_enabled True if mentions are enabled. * @return bool True if mentions scripts should be loaded. */ function bp_groups_maybe_load_mentions_scripts( $load_mentions, $mentions_enabled ) { if ( ! $mentions_enabled ) { return $load_mentions; } if ( $load_mentions || bp_is_group_activity() ) { return true; } return $load_mentions; } add_filter( 'bp_activity_maybe_load_mentions_scripts', 'bp_groups_maybe_load_mentions_scripts', 10, 2 ); /** * Disable at-mention notifications for users who are not a member of the non-public group where the activity appears. * * @since 2.5.0 * * @param bool $send Whether to send the notification. * @param array $usernames Array of all usernames being notified. * @param int $user_id ID of the user to be notified. * @param BP_Activity_Activity $activity Activity object. * @return bool */ function bp_groups_disable_at_mention_notification_for_non_public_groups( $send, $usernames, $user_id, BP_Activity_Activity $activity ) { // Skip the check for administrators, who can get notifications from non-public groups. if ( user_can( $user_id, 'bp_moderate' ) ) { return $send; } if ( 'groups' === $activity->component ) { $group = groups_get_group( $activity->item_id ); if ( 'public' !== $group->status && ! groups_is_user_member( $user_id, $group->id ) ) { $send = false; } } return $send; } /** * Use the mystery group avatar for groups. * * @since 2.6.0 * * @param string $avatar Current avatar src. * @param array $params Avatar params. * @return string */ function bp_groups_default_avatar( $avatar, $params ) { if ( isset( $params['object'] ) && 'group' === $params['object'] ) { if ( isset( $params['type'] ) && 'thumb' === $params['type'] ) { $file = 'mystery-group-50.png'; } else { $file = 'mystery-group.png'; } $avatar = buddypress()->plugin_url . "bp-core/images/$file"; } return $avatar; }