Skip to:
Content
Pages
Categories
Search
Top
Bottom

Cleaning up db after deleting group

  • For some reasons that I cannot understand, Buddypress seems not to clean up after itself when deleting groups. The desired functionality for me would be that all forums, topics, posts and meta-data belonging to the group being deleted also get removed from their respective tables, but this unfortunately does not occur (I’m using the Group Forums btw…). Is this the desired behaviour, a flaw or a bug?

    Not only that I find clogging db:s with unnecessary information bad, it also makes the development of a custom plugin for more advanced thread moving a lot harder for me since I now have to write my own clean ups. Is there a “delete_forum($forum_id)” or something similar that takes care of this? Or maybe any other function? Or am I completely missing something out here?

    WordPress Version 3.2.1
    BuddyPress Version 1.5.1

Viewing 4 replies - 1 through 4 (of 4 total)
  • bump…

    OK. Let me rephrase this… Has anyone had the same problem before and knows exactly which entries to remove from which tables?

    B.U.M.P.

    OK. I seem to have found a solution, so I’m gonna share it here:

    First, I replaced the groups_screen_group_admin_delete_group with a slightly changed version where I call a custom function after this line:
    `do_action( ‘groups_before_group_deleted’, $bp->groups->current_group->id );`

    Remember to register this correctly! In my case:
    `
    remove_action( ‘bp_screens’, ‘groups_screen_group_admin_delete_group’ );
    add_action( ‘bp_screens’, ‘myplugin_groups_screen_group_admin_delete_group’ );
    `

    where ‘myplugin_groups_screen_group_admin_delete_group’ is the name of the function.

    The function I call makes use of groups_delete_group_forum_topic( $topic_id ) and bb_delete_forum( $forum_id ). This way, you delete the group and keep the db tidy!
    `
    $forum_id_array = $wpdb->get_results($wpdb->prepare(“
    SELECT forum_id FROM wp_bb_forums
    WHERE forum_id = (
    SELECT meta_value
    FROM wp_bp_groups_groupmeta
    WHERE meta_key = ‘forum_id’
    AND group_id = %s
    ) ;”
    , $group_id));
    $forum_id = $forum_id_array[0]->forum_id;
    $topic_id_array = $wpdb->get_results($wpdb->prepare(“
    SELECT topic_id FROM wp_bb_posts
    WHERE forum_id = %s;”
    , $forum_id));

    foreach ($topic_id_array as $value) {
    groups_delete_group_forum_topic( $value->topic_id );
    }
    bb_delete_forum( $forum_id );
    `

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

You must be logged in to reply to this topic.