BuddyDev

Search

[Resolved] Hide members profile page, and prevent them from appearing in search results

  • Participant
    Level: Initiated
    Posts: 4
    JG on #23645

    Ok perfect! Thank you both so much 🙂 Last question, with the Deactivate plugin, is there a way to fully hide a deactivated users profile from other users? For instance, if I type in the URL of a user, I can still see their profile, but there’s a message that says they’re “currently inactive”…. I’d rather make it so that the profile page isn’t visible at all, and instead have the user redirected to another page of my choosing. Is this possible?

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #23647

    Hello JG,

    Yes, it can be easily done. Please use the following code to redirect to home page if user is inactive.

    
    /**
     * 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' );
    
    

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 3
    TeamEvilGSP on #41537
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #41550

    Hi Broderick,
    Please put the code in your child theme’s functions.php or you can use code snippets plugin for the same.
    https://wordpress.org/plugins/code-snippets/

    Regards
    Brajesh

  • 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

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #41561

    Hi,
    Thank you for the reply.

    I am sorry, I am unable to comment on the MemberPress code. The API used for the deactivator plugin is correct.

    Since you are using code from previous reply, I am assuming it should work.

    Regards
    Brajesh

  • 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.

  • Keymaster
    (BuddyDev Team)
    Posts: 24593
    Brajesh Singh on #41621

    Hi,
    Thank you for the rely.

    I am sorry but I am not sure why that would not work.

    Where did you find

    
    buddydev_activtate_user
    

    I am not seeing it being used on your previous post https://buddydev.com/support/forums/topic/hide-members-profile-page-and-prevent-them-from-appearing-in-search-results/page/2/#post-41554

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved