Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How to delete specific members from a large group?


  • palmdoc
    Participant

    @palmdoc

    In a large Buddypress group, if I want to delete a member, it’s very tedious to have to scroll through page after page of members in the Group Admin/Members or the WordPress Groups backend.
    Isn’t there a way to search then edit the group membership of individual members?

    Thanks

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

  • Henry Wright
    Moderator

    @henrywright

    There may be an easier way via the back-end (I haven’t checked) but via code you could do this in functions.php:

    
    function palmdoc_remove_group_user() {
        $group_id = 6 // Change this value
        $user_id = 320 // Change this value
        groups_leave_group( $group_id, $user_id );
    
    }
    add_action( 'init', 'palmdoc_remove_group_user' );

    The next time you visit your website in a browser, the user will be removed from the group.

    Whilst you’re not using it just comment out the add_action() part. For example:

    // add_action( 'init', 'palmdoc_remove_group_user' );


    danbp
    Participant

    @danbp

    hi @palmdoc,

    as expected by @henrywright, there is an easier solution from backend. I quickly tested it and it seems to work.

    The snippet will add a bulk option to members list (in admin), which let you remove users from groups. Like on front-end, the admin user list is searchable by user.

    Add this to bp-custom.php

    // remove users from groups
    add_action('load-users.php',function() {
    
    if(isset($_GET['action']) && isset($_GET['bp_gid']) && isset($_GET['users'])) {
        $group_id = $_GET['bp_gid'];
        $users = $_GET['users'];
        foreach ($users as $user_id) {
            groups_leave_group( $group_id, $user_id );
        }
    }
        //Add some Javascript to handle the form submission
        add_action('admin_footer',function(){ ?>
        <script>
            jQuery("select[name='action']").append(jQuery('<option value="groupleave">Remove from BP Group</option>'));
            jQuery("#doaction").click(function(e){
                if(jQuery("select[name='action'] :selected").val()=="groupleave") { e.preventDefault();
                    gid=prompt("Please enter a BuddyPres Group ID","");
                    jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit();
                }
            });
        </script>
        <?php
        });
    });

    palmdoc
    Participant

    @palmdoc

    Hi. Thanks for this.
    Sorry but a noob question: where is the bp-custom.php file? I can’t seem to locate it


    Henry Wright
    Moderator

    @henrywright

    /plugins/bp-custom.php

    If you don’t already have one, you should create one yourself.


    danbp
    Participant

    @danbp

    Codex is your friend:

    bp-custom.php


    palmdoc
    Participant

    @palmdoc

    Thanks!
    Done that but I can’t seem to find the new functions
    Is it supposed to be in
    mysite/groups/groupname/admin/manage-members/
    ?


    danbp
    Participant

    @danbp

    This page is on front-end: mysite/groups/groupname/admin/manage-members/

    The snippet is playing on the user list in admin. The access to delete a group user is in the bulk action selector, at the top left of that list.


    palmdoc
    Participant

    @palmdoc

    Hmm somehow I don’t see the selector. I have placed bp-custom.php in the root of the plugins folder

    and this is the code

    <?php
    // hacks and mods will go here
    // remove users from groups
    add_action('load-users.php',function() {
    
    if(isset($_GET['action']) && isset($_GET['bp_gid']) && isset($_GET['users'])) {
        $group_id = $_GET['bp_gid'];
        $users = $_GET['users'];
        foreach ($users as $user_id) {
            groups_leave_group( $group_id, $user_id );
        }
    }
        //Add some Javascript to handle the form submission
        add_action('admin_footer',function(){ ?>
        <script>
            jQuery("select[name='action']").append(jQuery('<option value="groupleave">Remove from BP Group</option>'));
            jQuery("#doaction").click(function(e){
                if(jQuery("select[name='action'] :selected").val()=="groupleave") { e.preventDefault();
                    gid=prompt("Please enter a BuddyPres Group ID","");
                    jQuery(".wrap form").append('<input type="hidden" name="bp_gid" value="'+gid+'" />').submit();
                }
            });
        </script>
        <?php
        });
    });
    ?>

    I wonder what I’m doing wrong?
    This is what I’m seeing:


    danbp
    Participant

    @danbp

    you’re on front-end, I’m talking about backend
    your-site/wp-admin/users.php


    palmdoc
    Participant

    @palmdoc

    Sorry but I don’t see any Group management options in the back end either. Can you please show a screenshot of what I’m supposed to see?


    danbp
    Participant

    @danbp

    Would you please read twice and triple check the answers you receive ? I added a screnshot and a link example you have to follow.

    Remeber that you asked for if I want to delete a member

    I suppose that you know how to manage users in admin ? Go there…


    palmdoc
    Participant

    @palmdoc

    I have read and checked more than three times. My original question is I want to delete a member from a group – i.e. remove them from a group not from the site.
    I really hope there is better group member management for Buddypress as it is a nightmare when there are thousands of members.


    danbp
    Participant

    @danbp

    Please, try the solution before telling insanity.

    Members bulk management is done in admin.
    To remove a group member, you have the opportunity to do it from frontend0. One by one, as mod or group admin. Why not bulk action on front ? Because it is not the place for achieve massive user administration.

    Back to backoffice where are
    A members list (with members)
    A group list (with group entities)

    Both allowg bulk actions (add/delete)
    If you check attentively, there is no relation between both list. No groups are mentionned on members list, and no members are mentionned on group list, except a member count.

    Now you’re coming in and ask how to bulk delete group members.
    Fortunately, you got a solution. No the best, not the only one, but at least, one.

    Alas, you didn’t really understand what to do with and where to use it. 3 topics and 2 screenshots later, explaining the difference between back and frontend, the only thing you find to say is I want to delete a member from a group not from the site.

    Do you really think that that code removes a site member ? Did you ever read the code ? Perhaps you don’t understand what groups_leave_group does ?
    This instruction removes only a member from one or more groups. Exactly that what you asked for. And it’s done from the only place where a members list is on hand: in admin.

    I close this topic, before getting totally out of scope and becaming to trollish.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] How to delete specific members from a large group?’ is closed to new replies.
Skip to toolbar