Changeset 11763 for trunk/src/bp-groups/bp-groups-filters.php
- Timestamp:
- 12/08/2017 12:22:09 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-filters.php
r11703 r11763 45 45 add_filter( 'bp_get_group_member_name', 'stripslashes' ); 46 46 add_filter( 'bp_get_group_member_link', 'stripslashes' ); 47 48 add_filter( 'groups_new_group_forum_desc', 'bp_create_excerpt' );49 47 50 48 add_filter( 'groups_group_name_before_save', 'force_balance_tags' ); … … 121 119 } 122 120 123 /** Legacy group forums (bbPress 1.x) *****************************************/124 125 /**126 * Filter bbPress query SQL when on group pages or on forums directory.127 *128 * @since 1.1.0129 */130 function groups_add_forum_privacy_sql() {131 add_filter( 'get_topics_fields', 'groups_add_forum_fields_sql' );132 add_filter( 'get_topics_join', 'groups_add_forum_tables_sql' );133 add_filter( 'get_topics_where', 'groups_add_forum_where_sql' );134 }135 add_filter( 'bbpress_init', 'groups_add_forum_privacy_sql' );136 137 /**138 * Add fields to bbPress query for group-specific data.139 *140 * @since 1.1.0141 *142 * @param string $sql SQL statement to amend.143 * @return string144 */145 function groups_add_forum_fields_sql( $sql = '' ) {146 $sql = 't.*, g.id as object_id, g.name as object_name, g.slug as object_slug';147 return $sql;148 }149 150 /**151 * Add JOINed tables to bbPress query for group-specific data.152 *153 * @since 1.1.0154 *155 * @param string $sql SQL statement to amend.156 * @return string157 */158 function groups_add_forum_tables_sql( $sql = '' ) {159 $bp = buddypress();160 161 $sql .= 'JOIN ' . $bp->groups->table_name . ' AS g LEFT JOIN ' . $bp->groups->table_name_groupmeta . ' AS gm ON g.id = gm.group_id ';162 163 return $sql;164 }165 166 /**167 * Add WHERE clauses to bbPress query for group-specific data and access protection.168 *169 * @since 1.1.0170 *171 * @param string $sql SQL Statement to amend.172 * @return string173 */174 function groups_add_forum_where_sql( $sql = '' ) {175 176 // Define locale variable.177 $parts = array();178 179 // Set this for groups.180 $parts['groups'] = "(gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id)";181 182 // Restrict to public...183 $parts['private'] = "g.status = 'public'";184 185 /**186 * ...but do some checks to possibly remove public restriction.187 *188 * Decide if private are visible189 */190 191 // Are we in our own profile?192 if ( bp_is_my_profile() )193 unset( $parts['private'] );194 195 // Are we a super admin?196 elseif ( bp_current_user_can( 'bp_moderate' ) )197 unset( $parts['private'] );198 199 // No need to filter on a single item.200 elseif ( bp_is_single_item() )201 unset( $parts['private'] );202 203 // Check the SQL filter that was passed.204 if ( !empty( $sql ) )205 $parts['passed'] = $sql;206 207 // Assemble Voltron.208 $parts_string = implode( ' AND ', $parts );209 210 $bp = buddypress();211 212 // Set it to the global filter.213 $bp->groups->filter_sql = $parts_string;214 215 // Return the global filter.216 return $bp->groups->filter_sql;217 }218 219 /**220 * Modify bbPress caps for bp-forums.221 *222 * @since 1.1.0223 *224 * @param bool $value Original value for current_user_can check.225 * @param string $cap Capability checked.226 * @param array $args Arguments for the caps.227 * @return bool228 */229 function groups_filter_bbpress_caps( $value, $cap, $args ) {230 231 if ( bp_current_user_can( 'bp_moderate' ) )232 return true;233 234 if ( 'add_tag_to' === $cap ) {235 $bp = buddypress();236 237 if ( $bp->groups->current_group->user_has_access ) {238 return true;239 }240 }241 242 if ( 'manage_forums' == $cap && is_user_logged_in() )243 return true;244 245 return $value;246 }247 add_filter( 'bb_current_user_can', 'groups_filter_bbpress_caps', 10, 3 );248 249 /**250 * Amends the forum directory's "last active" bbPress SQL query to stop it fetching information we aren't going to use.251 *252 * This speeds up the query.253 *254 * @since 1.5.0255 *256 * @see BB_Query::_filter_sql()257 *258 * @param string $sql SQL statement.259 * @return string260 */261 function groups_filter_forums_root_page_sql( $sql ) {262 263 /**264 * Filters the forum directory's "last active" bbPress SQL query.265 *266 * This filter is used to prevent fetching information that is not used.267 *268 * @since 1.5.0269 *270 * @param string $value SQL string to specify fetching just topic_id.271 */272 return apply_filters( 'groups_filter_bbpress_root_page_sql', 't.topic_id' );273 }274 add_filter( 'get_latest_topics_fields', 'groups_filter_forums_root_page_sql' );275 276 121 /** 277 122 * Should BuddyPress load the mentions scripts and related assets, including results to prime the
Note: See TracChangeset
for help on using the changeset viewer.