Skip to:
Content
Pages
Categories
Search
Top
Bottom

Incorrect friend count after user is deleted

  • Avatar of jody
    jody
    Participant

    @jcandothers

    After setting up a few users and testing what they can do. I noticed that the friend count was incorrect.
    If I am logged in as a user then add some friends. After they have accepted my friendship I then decide to just delete the account.
    The friend count is not updated for the users who were friends.

    bp_core_delete_account($user_id = false)
    only returns wp_delete_user($user_id);
    Is there supposed to be some clean up there before it returns?
    Maybe something just not coded yet?

    WP Version: 2.92
    BP Version: 1.2.3
    New Install

Viewing 5 replies - 1 through 5 (of 5 total)
  • Avatar of jody
    jody
    Participant

    @jcandothers

    Couldn’t find anything on this so I wrote something.
    It seems to work for me.
    I simply add this to the bp-custom.php

    function update_friends_count( $user_id ) {
    global $wpdb, $bp;
    if ($friend_ids = BP_Friends_Friendship::search_friends( ”, $user_id )) {
    foreach ($friend_ids AS $fid) {
    $total_sql = “SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE initiator_user_id = $fid OR friend_user_id = $fid”;
    $total_friend_ids = $wpdb->get_var($total_sql);
    update_usermeta($fid, ‘total_friend_count’, (int)($total_friend_ids) – 1);
    }
    }
    do_action( ‘update_friends_count’, $user_id );
    }
    add_action( ‘wpmu_delete_user’, ‘update_friends_count’, 1 );
    add_action( ‘delete_user’, ‘update_friends_count’, 1 );
    add_action( ‘make_spam_user’, ‘update_friends_count’, 1 );

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    @jcandothers – there is already a ticket about this:
    http://trac.buddypress.org/ticket/2341

    Please note your patch in that ticket. Login with the same credentials you use here on bp.org.

    Avatar of linusf
    linusf
    Participant

    @linusf

    @r-a-y
    I tried the solution presented in the ticket but with no luck, still counts removed users… I downloaded the file from http://trac.buddypress.org/changeset/2976.
    Is there something i´m missing here?

    Avatar of r-a-y
    r-a-y
    Moderator

    @r-a-y

    @linusf – So you applied the changes listed in the changeset and you still receive the wrong friend count? If so, please re-open the ticket.

    Avatar of linusf
    linusf
    Participant

    @linusf

    @r-a-y – Yes unfortunately. Hopefully someone can look at the ticket again.

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.