Changeset 7976
- Timestamp:
- 02/24/2014 02:08:24 AM (12 years ago)
- File:
-
- 1 edited
-
trunk/bp-groups/bp-groups-classes.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r7974 r7976 175 175 */ 176 176 public function populate() { 177 global $wpdb, $bp; 178 177 global $wpdb; 178 179 // Get BuddyPress 180 $bp = buddypress(); 181 182 // Check cache for group data 179 183 $group = wp_cache_get( $this->id, 'bp_groups' ); 184 185 // Cache missed, so query the DB 180 186 if ( false === $group ) { 181 187 $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) ); 182 188 } 183 189 184 if ( empty( $group ) ) { 190 // No group found so set the ID and bail 191 if ( empty( $group ) || is_wp_error( $group ) ) { 185 192 $this->id = 0; 186 193 return; 187 194 } 188 195 196 // Group found so setup the object variables 189 197 $this->id = $group->id; 190 198 $this->creator_id = $group->creator_id; … … 196 204 $this->date_created = $group->date_created; 197 205 206 // Are we getting extra group data? 198 207 if ( ! empty( $this->args['populate_extras'] ) ) { 199 $this->last_activity = groups_get_groupmeta( $this->id, 'last_activity' ); 208 209 // Set up some specific group vars from meta 210 $this->last_activity = groups_get_groupmeta( $this->id, 'last_activity' ); 200 211 $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' ); 201 212 … … 203 214 $admin_mods = $wpdb->get_results( apply_filters( 'bp_group_admin_mods_user_join_filter', $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id ) ) ); 204 215 216 // Add admins and moderators to their respective arrays 205 217 foreach ( (array) $admin_mods as $user ) { 206 if ( (int) $user->is_admin) {218 if ( !empty( $user->is_admin ) ) { 207 219 $this->admins[] = $user; 208 220 } else { … … 211 223 } 212 224 213 // Cache general (non-user-specific) 214 // information about the group 225 // Cache the group object before user-specific data is added 215 226 wp_cache_set( $this->id, $this, 'bp_groups' ); 216 } 217 218 // Set user-specific data 219 if ( ! empty( $this->args['populate_extras'] ) ) { 220 $this->is_member = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id ); 221 $this->is_invited = BP_Groups_Member::check_has_invite( bp_loggedin_user_id(), $this->id ); 222 $this->is_pending = BP_Groups_Member::check_for_membership_request( bp_loggedin_user_id(), $this->id ); 227 228 // Set user-specific data 229 $user_id = bp_loggedin_user_id(); 230 $this->is_member = BP_Groups_Member::check_is_member( $user_id, $this->id ); 231 $this->is_invited = BP_Groups_Member::check_has_invite( $user_id, $this->id ); 232 $this->is_pending = BP_Groups_Member::check_for_membership_request( $user_id, $this->id ); 223 233 224 234 // If this is a private or hidden group, does the current user have access? 225 if ( 'private' == $this->status || 'hidden' == $this->status ) { 226 if ( $this->is_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) ) 235 if ( ( 'private' === $this->status ) || ( 'hidden' === $this->status ) ) { 236 237 // Assume user does not have access to hidden/private groups 238 $this->user_has_access = false; 239 240 // Group members or community moderators have access 241 if ( ( $this->is_member && is_user_logged_in() ) || bp_current_user_can( 'bp_moderate' ) ) { 227 242 $this->user_has_access = true; 228 else 229 $this->user_has_access = false; 243 } 230 244 } else { 231 245 $this->user_has_access = true;
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)