BuddyDev

Search

[Resolved] How to remove buddypress user from all groups

Tagged: 

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #14126

    Hi Brajesh,

    Thanks for having a look at the code. I have a feeling that this happens via a cron job. I am waiting for response from developers I will let you know, thanks again.

    Kind regards,
    Mwale

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #14139

    No Problem. Please do let me know when you get a response from them.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #14144

    Hi Brajesh,

    the plugin support said to use something like this:

    function ms_subscription_expired_action( $subscription, $membership, $member ){
        //Do stuff
    }
    add_action( 'ms_subscription_status-' . MS_Model_Relationship::STATUS_EXPIRED, 'ms_subscription_expired_action', 10, 3 );

    Kind regards,
    Mwale

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #14151

    Hi Mwale,
    In that case, you can use my code from here

    https://buddydev.com/support/forums/topic/how-to-remove-buddypress-user-from-all-groups/#post-13894

    and change this line

    
    add_action( 'ms_model_event_deactivated', 'mwale_remove_from_group_on_membership_deactivate', 10, 2 );
    
    

    to

    
    add_action( 'ms_subscription_status-' . MS_Model_Relationship::STATUS_EXPIRED, 'mwale_remove_from_group_on_membership_deactivate', 10, 2 );
    
    

    That should most probably work.

    Please give it a try.

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #14157

    Hello Brajesh,

    Unfortunately that leads to a white blank screen. But I have a feeling that we almost have it. What could be the issue?

    The entire code I added is this:

    function mwale_remove_from_group_on_membership_deactivate( $event, $subscription ) {
    	$member = $subscription->get_member();
    	$user   = $member->get_user();
    	if ( ! $user || is_a( $user, 'WP_User' ) ) {
    		return;
    	}
    
    	groups_remove_data_for_user( $user->ID );
    
    }
    
    add_action( 'ms_subscription_status-' . MS_Model_Relationship::STATUS_EXPIRED, 'mwale_remove_from_group_on_membership_deactivate', 10, 2 );

    Warm regards,
    Mwale

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #14169

    Please check the error log and post me what error do you see there?

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #14179

    Hi Brajesh,

    Thanks for the advice. I checked the error. I fixed it simply by moving code from custom-plugin.php to functions.php .

    The site is not crashing anymore, but the code doesn’t seem to be doing what it is supposed to do.

    Kind regards,
    Mwale

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #14208

    Sorry about this. 3rd party plugin support, specially ones that we don’t use is tricky.

    I hope that the original plugin developers will assist you with proper action.

    The part of code

    
    groups_remove_data_for_user( $user->ID );
    

    Is guaranteed to remove the user from all groups but it seems I am not using the correct hook to attach to.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 21
    Mwale on #14861

    Hi Brajesh,

    I want to say thank you very much for helping me on this topic. Unfortunately I have not been able to make the best(more efficient) solution work, so I am using the inefficient code here: https://buddydev.com/support/forums/topic/how-to-remove-buddypress-user-from-all-groups/#post-14107 . This is the solution I am currently using. As such I am marking this topic as solved, thanks again.

    Kind regards,
    Mwale

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #14879

    Hi Mwale,
    No problem.

    I am sorry that I could not do much with a 3rd party plugin.

    It’s fine to use that code but I am a bit purist and I won’t.

    Regards
    Brajesh

The topic ‘ [Resolved] How to remove buddypress user from all groups’ is closed to new replies.

This topic is: resolved