User registration on subsite in multisite configuration

The multisite setup allows you to enable and disable user registration at the network level but if you see the database it store the value in the wp_options tables for each site.

So we can try the below and see if this work.

Use the below code in the functions.php file.

function wpse_enable_user_registration( $blog_id = 1 ) {
    switch_to_blog( $blog_id );
    // Fetching the present option
    $user_registration_option = get_option( 'users_can_register', 0 );

    if( '0' == $user_registration_option )
        $site_registration_option = update_option( 'users_can_register', 1 );

    restore_current_blog(); // Switches back to the original blog

    return $site_registration_option;
}

If the updation is successful, you will get true else false

Now you can use the function to enable any subsites in the MU setup by passing the sub sites id to the function in place of $blog_id

Leave a Comment