BuddyDev

Search

Replies

  • Participant
    Level: Initiated
    Posts: 3
    TeamEvilGSP on #41564

    Hi Brajesh,
    Thanks so much for your reply. Unfortunately inserting the code above, including the code from the previous reply didn’t enable us to auto-activate/deactivate accounts whenever MemberPress subscriptions change
    Also, may we check the spelling here:
    buddydev_activtate_user
    If there is any way to use the plugin to do this it would be amazing, as manually changing each member setting would be very time-consuming.
    I have also reached out to Buddyboss and they are aware the Buddyboss platform doesn’t have this function.
    I also reached out to Memberpress and they said they will be introducing some code changes that, as a result, will show active and inactive subscriptions in separate tabs.
    The change should be in the next stable release of MemberPress and in one of the upcoming “Edge” release that should be available by the end of this month at the latest, probably sooner.

  • Participant
    Level: Initiated
    Posts: 3
    TeamEvilGSP on #41554

    Hi Brajesh,

    Thanks so much for your response and awesome plugin.

    We have placed the following in buddyboss child theme’s functions.php

     function mepr_sync_buddy_press_visibility($txn, $status = false) {
      global $buddyPress;
      if(class_exists('MeprUser')) {
    
        $user = new MeprUser($txn->user_id);
        $subs = $user->active_product_subscriptions();
    
        if(!empty($subs)) {
          $buddyPress->unblock_account($user->ID);
        }
        else {
          $buddyPress->block_account($user->ID);
        }
      }
    }
    add_action('mepr-txn-store', 'mepr_sync_buddy_press_visibility');
    add_action('mepr-txn-expired', 'mepr_sync_buddy_press_visibility', 11, 2);
    
    function buddydev_activate_user( $txn ) {
    
    	if ( function_exists( 'bp_account_deactivator' ) && bp_account_deactivator()->is_inactive( $txn->user_id ) ) {
    		bp_account_deactivator()->set_active( $txn->user_id );
    	}
    }
    add_action( 'mepr-txn-status-complete', 'buddydev_activate_user' );
    
    function buddydev_deactivate_user( $txn ) {
    
    	if ( function_exists( 'bp_account_deactivator' ) && bp_account_deactivator()->is_active( $txn->user_id ) ) {
    		$active_subscription_count = MeprSubscription::get_all_active_by_user_id( $txn->user_id, '', '', true );
    
    		if ( empty( $active_subscription_count ) ) {
    			bp_account_deactivator()->set_inactive( $txn->user_id );
    		}
    	}
    }
    
    add_action( 'mepr-txn-status-refunded', 'buddydev_deactivate_user', 20 );
    add_action( 'mepr-transaction-expired', 'buddydev_deactivate_user', 20 );
    
    /**
     * Redirect user if account is deactivated.
     */
    function buddydev_redirect_from_inactive_users_profile() {
    	// do not redirect if not in single user page or my profile page.
    	if ( ! bp_is_user() || bp_is_my_profile() || is_super_admin() ) {
    		return;
    	}
    
    	if ( function_exists('bp_account_deactivator') && bp_account_deactivator()->is_inactive( bp_displayed_user_id() ) ) {
    		// Redirect on homepage.
    		bp_core_redirect( home_url() );
    	}
    }
    add_action( 'bp_template_redirect', 'buddydev_redirect_from_inactive_users_profile' ); 

    is this correct?
    Thanks so much for your assistance

  • Participant
    Level: Initiated
    Posts: 3
    TeamEvilGSP on #41537
    This reply has been marked as private.