WordPress.org

Ready to get started?Download WordPress

Forums

Groups
[resolved] How to programatically remove a user to a group (4 posts)

  1. mirgcire
    Member
    Posted 2 months ago #

    I am working on a site that allows students to enroll in classes. When they enroll in a class, I want to automatically add them to the class group. And if they cancel the enrollment, I want to automatically remove them.

    I found this in the documentation

    Groups_User_Group::create( array( 'user_id' => $user_id, 'group_id' => $group_id ) );

    After digging in the source a little, I am guessing that this is the way to remove:

    Groups_User_Group::delete ( $user_id, $group_id ) );

    https://wordpress.org/plugins/groups/

  2. itthinx
    Member
    Plugin Author

    Posted 2 months ago #

  3. mirgcire
    Member
    Posted 2 months ago #

    I am attempting to use Groups_User_Group::create. But it is not working.
    So, I added some debug messages to this function to see what is going on.

    I have a group called '2014Q3-DC0' and it is visible in the admin panel. When I entered create my error_log message printed the user id and group id correctly, however results of Group_Group::read($group_id) was empty.

    Do you have any suggestions for further analysis?

    Thanks!

  4. mirgcire
    Member
    Posted 2 months ago #

    I was skimming through your code and found another function called read_by_name.

    I used this to convert the group name into a group id.

    Then (after fixing a couple more bugs) everything magically worked!

    Thanks

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.