itthinx / groups

Groups provides group-based user membership management, group-based capabilities and content access control. It integrates standard WordPress capabilities and application-specific capabilities along with an extensive API.
GNU General Public License v3.0
49 stars 35 forks source link

Automatically remove a group upon user activation #52

Closed sethburtonhall closed 7 years ago

sethburtonhall commented 8 years ago

I have a Gravity membership registration form that assigns a "Pending" group upon submission.

As of now, the admin manually removes the "Pending" group once they activate the member, but I am wondering if it is possible to automatically remove that "Pending" group from the user once the admin activates their account?

JoryHogeveen commented 7 years ago

Hi @middle8media

I don't think it's easy to build this logic automatically since this case could vary a lot for each implementation of Groups.

You could simply do this when a user is updated (or in your case activated).

add_action( 'profile_update', 'my_theme_remove_pending_group' );
function my_theme_remove_pending_group() {
    $activated = false;
    // << Check if your user is activated or not. Not sure how your activation process is working so can't provide you this code..

    if ( true == $activated ) {
        $group_id = 1; // << change this to the ID of the "Pending" group

        // Here we delete this user from the "Pending" group
        Groups_User_Group::delete( $user_id, $group_id );
    }
}