BuddyDev

Search

[Resolved] How to limit buddypress registrations

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #30293

    Hello,

    I want to limit registrations on my site to create artificial scarcity. How can I redirect guests to another page when my site membership hits 5,000 members.

    1. Site reaches 5,000 registered members
    2. Guests trying to access buddypress registration page after attaining 5,000 members are automatically redirected to another custom page with url slug (sign-up-closed)

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #30294

    Hello Tosin,

    Thank you for posting. Try the following code.

    
    add_action( 'bp_template_redirect', function () {
    	if ( bp_is_register_page() ) {
                // Check your conditions here. home_url to you page url.
    		bp_core_redirect( home_url() );
    	}
    } );
    

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #30296

    Thanks for the reply but I dont really know how to code and how to check for the conditions

    The conditons needed are
    1. User must be a guest or logged out
    2. Total site members must be 5,000
    3. redirect to page with ID 45565

    Thank you

    • This reply was modified 2 years, 4 months ago by Tosin.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #30303

    Hello Tosin,

    Please try the following code. It will redirect new users to page with id ‘45565’

    
    add_action( 'bp_template_redirect', function () {
    
    	// If logged in nothing to do with it.
    	if ( is_user_logged_in() || ! bp_is_register_page() ) {
    		return;
    	}
    
    	$site_users = get_users( array( 'fields' => 'ID' ) );
    
    	$site_users_count = count( $site_users );
    
    	// If site user count is less than 5000 not need to redirect.
    	if ( 5000 > $site_users_count ) {
    		return;
    	}
    
    	// Check your conditions here. home_url to you page url.
    	bp_core_redirect( get_page_link( 45565 ) );
    } );
    
    

    Please let me know if it works or not. One more question, Are you working with multisite then there will be a slight change?

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #30305

    The code did not work and I am not using multisite

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #30308

    Hello Tosin,

    Please make sure page with mentioned id is in published state and site user count is greater than 5000 only then this code will work.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 701
    Tosin on #30309

    It worked perfectly now thanks a lot Ravi, im really gratefull

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2459
    Ravi on #30310

    Hello Tosin,

    Thank you for the acknowledgement. I am glad that I could help.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved