As a network admin in multisite configuration, I have the option to enable or disable the user registration \ site registration. is there any way i can enable the user registration on s single sub site , not on all sites.
In my WP setup, I have a main blog which is managed by me and I dont want user to register here. i have a another blog installed on sub directory dedicated for forum. I would like to enable user registration here, so that user can use the forum
As a network admin in multisite configuration, I have the option to enable or disable the user registration \ site registration. is there any way i can enable the user registration on s single sub site , not on all sites.
In my WP setup, I have a main blog which is managed by me and I dont want user to register here. i have a another blog installed on sub directory dedicated for forum. I would like to enable user registration here, so that user can use the forum
Share Improve this question asked Nov 26, 2013 at 14:02 acracr 1331 silver badge4 bronze badges 4- Did you try the settings at the individual site level? That should work independently – Maruti Mohanty Commented Nov 26, 2013 at 14:06
- 1 There is no option to set user registration in individual sites – acr Commented Nov 26, 2013 at 14:27
- oh yes you are right... My bad :) – Maruti Mohanty Commented Nov 26, 2013 at 14:45
- 1 As you have found WordPress on its own doesn't allow sub-site registration and many of the plugins expect the user to belong to the main site at least before granting other sub-sites. There is a new plugin network-subsite-user-registration which does want you are after. – Justin Commented Mar 19, 2017 at 21:31
2 Answers
Reset to default 2The 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
Multisite adds a filter for get_option('users_can_register')
calls in ms-functions.php
users_can_register_signup_filter
. This filter circumvents any blog-level settings you try to implement.
/**
* Check whether users can self-register, based on Network settings.
*
* @since MU
*
* @return bool
*/
function users_can_register_signup_filter() {
$registration = get_site_option('registration');
if ( $registration == 'all' || $registration == 'user' )
return true;
return false;
}
add_filter('option_users_can_register', 'users_can_register_signup_filter');