Skip to:
Content

BuddyPress.org

Changeset 2976


Ignore:
Timestamp:
04/29/2010 09:11:02 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Fixes #2341

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.2/bp-friends/bp-friends-classes.php

    r2362 r2976  
    127127        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id ) );
    128128
    129         if ( !$count )
     129        // Do not update meta if user has never had friends
     130        if ( !$count && !get_usermeta( $user_id, 'total_friend_count' ) )
    130131            return 0;
    131132
    132         update_usermeta( $user_id, 'total_friend_count', $count );
    133         return $count;
     133        update_usermeta( $user_id, 'total_friend_count', (int)$count );
     134        return (int)$count;
    134135    }
    135136
     
    315316        global $wpdb, $bp;
    316317
     318        // Delete all friendships related to $user_id
    317319        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id ) );
    318320
    319321        // Delete friend request notifications for members who have a notification from this user.
    320322        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id ) );
     323
     324        // Get friends of $user_id and update their respective friend counts
     325        $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );
     326        foreach ( (array)$friend_ids as $friend_id )
     327            BP_Friends_Friendship::total_friend_count( $friend_id );
     328
    321329    }
    322330}
Note: See TracChangeset for help on using the changeset viewer.