Disable Site Registration for BuddyPress

Sybre Waaijer on August 14, 2015

About BuddyPress

BuddyPress is a simply awesome user management system that allows you to interact with users in various ways.

I can elaborate about BuddyPress more, but you’re here for something else. Let’s get to it.

Disable Site Registration

Unfortunately undocumented, disabling site registration on BuddyPress seems impossible.
Especially if you allow BuddyPress instances to be run by your users without Network Activation.

You’ll get many spam sites as well if the sites with BuddyPress are indexed, so let’s remove remove the site registration option all together from all sites using BuddyPress but the main blog.
I won’t go into detail here since all functions speak for themself. But we need to return an array to bp_core_get_root_options.

Add this as a plugin and network activate it or either add this as a mu-plugin:

<?php
/**
 * Plugin Name: Disable BuddyPress Site Registration
 * Plugin URI: https://hostmijnpagina.nl
 * Description: Disables blog signup in BuddyPress.
 * Version: 1.0.0
 * Author: Sybre Waaijer
 * Author URI: https://cyberwire.nl/
 * License: GPLv2 or later
 */

// We're using a plugable function is_main_site(), so we need init first.
add_action( 'init', 'dbs_disable_buddypress_sites' );

function dbs_disable_buddypress_sites() {
    if ( !is_main_site() ) {
        add_filter( 'wpmu_active_signup', 'dbs_disable_active_signup_option', 11 );
        add_filter( 'bp_core_get_root_options', 'dbs_disable_active_signup_array', 11); // This is the key we wanted.
        
        // The following filters are untested but should work in weird scenarios. Uncomment them if you're still seeing the site registration option.
//        add_filter( 'bp_core_network_options', 'dbs_disable_active_signup_array', 11);
//        add_filter( 'bp_get_default_options', 'dbs_disable_active_signup_array', 11);
    }
}

function dbs_disable_active_signup_option() {
    $active_signup = 'user'; //set to 'none' to completely disable the signup page.
    
    return $active_signup; 
}

function dbs_disable_active_signup_array() {
    $args['registration'] = 'user'; //set to 'none' to completely disable the signup page.
    
    return $args;
}

Enjoy!

Leave a Reply

Your email address will not be published.