Skip to:
Content

BuddyPress.org

Opened 13 months ago

Last modified 8 weeks ago

#9057 assigned enhancement

Make BP Signups a Member's component deactivable feature

Reported by: shawfactor's profile shawfactor Owned by: imath's profile imath
Milestone: Up Next Priority: high
Severity: normal Version: 2.0
Component: Members Keywords: has-patch has-unit-tests needs-testing
Cc:

Description

Right now register is a fully fledged comonent but it is not listed in options-general.php?page=bp-components and cannot be deactivated.

This is not ideal as users may want to use non buddypress ways to register users some of which (e.g. registering via a third party like google) are much lower friction. These methods usually require registration to be open so it is not a question of toggling the global setting

Change History (19)

#1 @imath
13 months ago

  • Component changed from Core to Members
  • Milestone changed from Awaiting Review to 14.0.0

Thanks for your feedback, I agree about giving the choice to admin, see #9046

I’m unsure about the how, moving signups out of the members component to make it a separate one seems a bit too much to me. I was more thinking to an option. But let’s discuss about it during 14.0.0 dev cycle.

This ticket was mentioned in Slack in #buddypress by imath. View the logs.


12 months ago

#3 @teeboy4real
12 months ago

Hello @imath

I really like this idea and I would also like to add suggestion of the ability to control registrations based on a set threshold or number of already registered members. I would love to share my personal custom code with you so you can review it and improve on it. Adding this to core would be really awesome.

For example disable registrations when community has reached a threshold of 10,000 registered members

Thanks

<?php
/*
* Plugin Name: BuddyPress Registration Control
* Description: Allows administrators to enable or disable user registration and select a URL to redirect to when registration is disabled.
* Version: 1.0
*/

// Register the new setting in the BuddyPress options group
function custom_bp_register_settings() {
    if ( ! function_exists( 'bp_is_active' ) ) {
        return;
    }
    register_setting( 'buddypress', 'bp-disable-site-registration', 'custom_bp_sanitize_registration_status' );
    register_setting( 'buddypress', 'bp-disable-site-registration-redirection-url', 'custom_bp_sanitize_redirection_url' );
    register_setting( 'buddypress', 'bp-close-registration-at-users', 'custom_bp_sanitize_user_registration_count' );
}
add_action( 'admin_init', 'custom_bp_register_settings' );

// add sanitization function
function custom_bp_sanitize_registration_status( $status ) {
    $allowed_values = array( 'open', 'closed' );
    if ( ! in_array( $status, $allowed_values ) ) {
        $status = 'open';
    }
    return $status;
}

function custom_bp_sanitize_redirection_url( $url ) {
    return esc_url_raw( $url, null, 'db' );
}

function custom_bp_sanitize_user_registration_count( $count ) {
    return absint( $count );
}

// Add the new setting to the BuddyPress options page
function custom_bp_add_settings_field() {
    if ( ! function_exists( 'bp_is_active' ) ) {
        return;
    }
        add_settings_field(
        'bp-disable-site-registration',
        __( 'Registration', 'buddypress' ),
        'custom_bp_settings_field_html',
        'buddypress',
        'bp_main',
        array(
            'label_for' => 'bp-disable-site-registration',
        )
    );
    add_settings_field(
        'bp-disable-site-registration-redirection-url',
        __( 'Redirection URL', 'buddypress' ),
        'custom_bp_settings_redirection_url_html',
        'buddypress',
        'bp_main',
        array(
            'label_for' => 'bp-disable-site-registration-redirection-url',
        )
    );
    add_settings_field( 
        'bp-close-registration-at-users',
        __( 'Limit User Registration Count', 'buddypress' ),
        'custom_bp_close_registration_at_users_html',
        'buddypress',
        'bp_main',
        array(
            'label_for' => 'bp-close-registration-at-users',
        )
    );
}
add_action( 'bp_register_admin_settings', 'custom_bp_add_settings_field', 10, 1 );

// Output the HTML for the setting field
function custom_bp_settings_field_html() {
    $value = get_option( 'bp-disable-site-registration', 'open' );
    ?>
    <select name="bp-disable-site-registration" id="bp-disable-site-registration">
        <option value="open" <?php selected( $value, 'open' ); ?>><?php _e( 'Open', 'buddypress' ); ?></option>
        <option value="closed" <?php selected( $value, 'closed' ); ?>><?php _e( 'Closed', 'buddypress' ); ?></option>
    </select>
    <?php
}

// Output the HTML for the redirection URL field
function custom_bp_settings_redirection_url_html() {
    $value = get_option( 'bp-disable-site-registration-redirection-url', home_url() );
    ?>
    <input type="text" name="bp-disable-site-registration-redirection-url" id="bp-disable-site-registration-redirection-url" value="<?php echo esc_attr( $value ); ?>" required/>
    <?php
}

// Output the HTML for the close registration at users field
function custom_bp_close_registration_at_users_html() {
    $value = get_option( 'bp-close-registration-at-users' );
    ?>
    <input type="number" name="bp-close-registration-at-users" id="bp-close-registration-at-users" value="<?php echo esc_attr( $value ); ?>" required/>
    <p class="description"><?php _e( 'Enter the maximum number of users allowed to register on the site. Leave it empty or set to 0 for no limit.', 'buddypress' ); ?></p>
    <?php
}

// Check if registration is open or closed
function custom_bp_redirect_registration() {
	if ( ! bp_is_register_page() ) {
		return;
	}
	if ( get_option( 'bp-disable-site-registration', 'open' ) !== 'closed' ) {
		return;
	}
	$total_users                   = count_users();
	$total_users                   = $total_users['total_users'];
	$limit_user_registration_count = absint( get_option( 'bp-close-registration-at-users' ) );

	if ( $total_users >= $limit_user_registration_count ) {
		wp_redirect( get_option( 'bp-disable-site-registration-redirection-url' ) ); // wp_safe_redirect?
		exit;
	}
}
add_action( 'bp_screens', 'custom_bp_redirect_registration' );
Last edited 12 months ago by teeboy4real (previous) (diff)

#4 @imath
12 months ago

Hi @teeboy4real

Thanks for your feedback, suggestion & code. I’ll look at it asap 👍

#5 @imath
11 months ago

  • Owner set to imath
  • Status changed from new to assigned

This ticket was mentioned in Slack in #buddypress by emaralive. View the logs.


10 months ago

#7 @imath
10 months ago

  • Keywords needs-patch added
  • Summary changed from Make register a deactivatable component to Make BP Signups a Member's component deactivable feature
  • Version set to 2.0

This ticket was mentioned in Slack in #buddypress by imath. View the logs.


8 months ago

This ticket was mentioned in Slack in #buddypress by dcavins. View the logs.


7 months ago

#10 @imath
7 months ago

  • Milestone changed from 14.0.0 to Up Next

We need more time, sorry to postpone this to next major release.

#11 @imath
7 months ago

  • Milestone changed from Up Next to 15.0.0

This ticket was mentioned in Slack in #buddypress by imath. View the logs.


5 months ago

#13 @espellcaste
5 months ago

  • Priority changed from normal to high

This ticket was mentioned in Slack in #buddypress by espellcaste. View the logs.


4 months ago

This ticket was mentioned in PR #386 on buddypress/buddypress by @imath.


3 months ago
#15

  • Keywords has-patch has-unit-tests added; needs-patch removed

This PR introduces a way to completely disable BuddyPress signups using the following filter:

add_filter( 'bp_is_members_signups_active', '__return_false' );

Once this filter is in place:

  • The registration workflow used is the one provided by WordPress.
  • The Admin screen to manage pending accounts is not available.
  • The Admin/Tools screen about invitations and optouts are disabled.
  • Options to allow site invitations or site memberships are disabled.

I'd need @dcavins to check everything is fine if a user tries to reach a front-end screen about site invitations or site memberships. In particular, I believe there's still work to do in the case the above filter was added after site invitations or site memberships were allowed from BuddyPress settings.

I've currently tested on a regular WordPress config:

  • registering when the Members component signups feature is active.
  • registering when the Members component signups feature is not active.

We need more testing for Multisite configs.

Some parts of this PR code is duplicating with https://github.com/buddypress/buddypress/pull/368: mainly the BP_Component_Feature class.

Trac ticket: https://buddypress.trac.wordpress.org/ticket/9057

#16 @imath
3 months ago

  • Keywords needs-testing added

This ticket was mentioned in Slack in #buddypress by imath. View the logs.


3 months ago

#18 @dcavins
3 months ago

@imath What would we expect to happen in the case I think you're describing above?

  • User is sent a site invitation or makes a membership request (and the request is accepted--so the activation link is sent to the user)
  • Admin completely disables BP signup
  • User tries to accept invitation or follow activation link
  • What should happen?

I think that if the admin has deactivated BP signups, then the invitation or activation should fail, since that refers back to a now-disabled method. What do you think?

Last edited 3 months ago by dcavins (previous) (diff)

#19 @espellcaste
8 weeks ago

  • Milestone changed from 15.0.0 to Up Next
Note: See TracTickets for help on using tickets.