Skip to:
Content

BuddyPress.org

Changeset 7974


Ignore:
Timestamp:
02/23/2014 08:44:26 PM (11 years ago)
Author:
boonebgorges
Message:

Fix logic error in caching in BP_Groups_Group::populate()

Introduced in r7956, this bug cause the populate logic not to be run when
the cache was hit successfully. Mega-anti-props boonebgorges.

See #5407

File:
1 edited

Legend:

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

    r7956 r7974  
    180180        if ( false === $group ) {
    181181            $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) );
    182 
    183             if ( empty( $group ) ) {
    184                 $this->id = 0;
    185                 return;
     182        }
     183
     184        if ( empty( $group ) ) {
     185            $this->id = 0;
     186            return;
     187        }
     188
     189        $this->id           = $group->id;
     190        $this->creator_id   = $group->creator_id;
     191        $this->name         = stripslashes( $group->name );
     192        $this->slug         = $group->slug;
     193        $this->description  = stripslashes( $group->description );
     194        $this->status       = $group->status;
     195        $this->enable_forum = $group->enable_forum;
     196        $this->date_created = $group->date_created;
     197
     198        if ( ! empty( $this->args['populate_extras'] ) ) {
     199            $this->last_activity      = groups_get_groupmeta( $this->id, 'last_activity' );
     200            $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );
     201
     202            // Get group admins and mods
     203            $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
     205            foreach ( (array) $admin_mods as $user ) {
     206                if ( (int) $user->is_admin ) {
     207                    $this->admins[] = $user;
     208                } else {
     209                    $this->mods[] = $user;
     210                }
    186211            }
    187212
    188             $this->id           = $group->id;
    189             $this->creator_id   = $group->creator_id;
    190             $this->name         = stripslashes( $group->name );
    191             $this->slug         = $group->slug;
    192             $this->description  = stripslashes( $group->description );
    193             $this->status       = $group->status;
    194             $this->enable_forum = $group->enable_forum;
    195             $this->date_created = $group->date_created;
    196 
    197             if ( ! empty( $this->args['populate_extras'] ) ) {
    198                 $this->last_activity      = groups_get_groupmeta( $this->id, 'last_activity' );
    199                 $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );
    200 
    201                 // Get group admins and mods
    202                 $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 ) ) );
    203 
    204                 foreach ( (array) $admin_mods as $user ) {
    205                     if ( (int) $user->is_admin ) {
    206                         $this->admins[] = $user;
    207                     } else {
    208                         $this->mods[] = $user;
    209                     }
    210                 }
    211 
    212                 // Cache general (non-user-specific)
    213                 // information about the group
    214                 wp_cache_set( $this->id, $this, 'bp_groups' );
    215             }
    216 
    217             // Set user-specific data
    218             if ( ! empty( $this->args['populate_extras'] ) ) {
    219                 $this->is_member  = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id );
    220                 $this->is_invited = BP_Groups_Member::check_has_invite( bp_loggedin_user_id(), $this->id );
    221                 $this->is_pending = BP_Groups_Member::check_for_membership_request( bp_loggedin_user_id(), $this->id );
    222 
    223                 // If this is a private or hidden group, does the current user have access?
    224                 if ( 'private' == $this->status || 'hidden' == $this->status ) {
    225                     if ( $this->is_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) )
    226                         $this->user_has_access = true;
    227                     else
    228                         $this->user_has_access = false;
    229                 } else {
     213            // Cache general (non-user-specific)
     214            // information about the group
     215            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 );
     223
     224            // 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' ) )
    230227                    $this->user_has_access = true;
    231                 }
     228                else
     229                    $this->user_has_access = false;
     230            } else {
     231                $this->user_has_access = true;
    232232            }
    233233        }
Note: See TracChangeset for help on using the changeset viewer.