BuddyDev

Search

[Resolved] BP deactivate account plugin and Paid Membership Pro question.

  • Participant
    Level: Initiated
    Posts: 1
    Mark on #4889

    Hi, I really like this plugin and would like to automatically set the account status to deactivated when a member cancels their membership in Paid Membership Pro.

    I use the following function (fyi, I simplified it for this question)to do stuff when a member changes their membership level status.

    Could you help me with the code I would need to add to the last elseif section for cancelling memberships to deactivate their BP status? Note, when they cancel, I am not removing the user from the backend, in case they want to rejoin later and still have their historical info.

    Second question, when we do this, if I user re-signs back up for Level 1 or 2, do I need to reset their account status back to active or will that happen automatically?

    Thanks for your help.

    function my_pmpro_after_change_membership_level($level_id){

    if(!isset($user_id)){
    $user = wp_get_current_user();
    $user_id = $user->id;
    }

    // get user object
    $wp_user_object = new WP_User($user_id);

    // ignore admins
    if(in_array(“administrator”, $wp_user_object->roles)){
    return;
    }

    if($level_id == 1){

    // New member of level #1. Give them subscriber role.
    $wp_user_object->set_role(‘subscriber’);

    }elseif($level_id == 2){

    // New member of level #2. Give them Vendor role.
    $wp_user_object->set_role(‘vendor’);

    }elseif($level_id == 0){
    //Cancelling Membership. Give them Subscriber role.
    $wp_user_object->set_role(‘subscriber’);
    }
    }
    add_action(“pmpro_after_change_membership_level”, “my_pmpro_after_change_membership_level”);

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #4890

    Hi Mark,
    Thank you for posting.
    Here is the code that you can use

    
    
    if ( function_exists( 'bp_account_deactivator' ) ) {
    	bp_account_deactivator()->set_inactive( $user_id );
    }
    
    

    Hope that helps.

  • Participant
    Level: Initiated
    Posts: 1
    Mark on #4906

    Hi that worked. What is the code to set to auto activate? Would I just change the code to
    bp_account_deactivator()->set_active( $user_id );

    Also,
    The message that say “Your account in inactive…” should say “Your account is inactive…”. Just a small typo I noticed and fixed in my plugin install.

  • Keymaster
    (BuddyDev Team)
    Posts: 24190
    Brajesh Singh on #4912

    Hi Mark,
    Thank you.
    yes, The code to set active is

    
    bp_account_deactivator()->set_active( $user_id );
    
    

    Also, I have updated the plugin and fixed the typo in 1.0.3.

    Thank you
    Brajesh

The topic ‘ [Resolved] BP deactivate account plugin and Paid Membership Pro question.’ is closed to new replies.

This topic is: resolved