Skip to:
Content

BuddyPress.org

Changeset 7976


Ignore:
Timestamp:
02/24/2014 02:08:24 AM (12 years ago)
Author:
johnjamesjacoby
Message:

Inline doc, code formatting, and micro-optimizations to BP_Groups_Group::populate().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r7974 r7976  
    175175         */
    176176        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
    179183                $group = wp_cache_get( $this->id, 'bp_groups' );
     184
     185                // Cache missed, so query the DB
    180186                if ( false === $group ) {
    181187                        $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) );
    182188                }
    183189
    184                 if ( empty( $group ) ) {
     190                // No group found so set the ID and bail
     191                if ( empty( $group ) || is_wp_error( $group ) ) {
    185192                        $this->id = 0;
    186193                        return;
    187194                }
    188195
     196                // Group found so setup the object variables
    189197                $this->id           = $group->id;
    190198                $this->creator_id   = $group->creator_id;
     
    196204                $this->date_created = $group->date_created;
    197205
     206                // Are we getting extra group data?
    198207                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'      );
    200211                        $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );
    201212
     
    203214                        $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 ) ) );
    204215
     216                        // Add admins and moderators to their respective arrays
    205217                        foreach ( (array) $admin_mods as $user ) {
    206                                 if ( (int) $user->is_admin ) {
     218                                if ( !empty( $user->is_admin ) ) {
    207219                                        $this->admins[] = $user;
    208220                                } else {
     
    211223                        }
    212224
    213                         // Cache general (non-user-specific)
    214                         // information about the group
     225                        // Cache the group object before user-specific data is added
    215226                        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 );
    223233
    224234                        // 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' ) ) {
    227242                                        $this->user_has_access = true;
    228                                 else
    229                                         $this->user_has_access = false;
     243                                }
    230244                        } else {
    231245                                $this->user_has_access = true;
Note: See TracChangeset for help on using the changeset viewer.