Limit one blog per user

Hi

I am trying to limit each user to be able to signup for only one site in my Multisite website. However, I am encountering a very strange problem. Previously I added the following codes which I obtained from a forum here and it worked perfectly for more than 2 months with more than 50 test sites created. Here's the code I used:

function ds_one_blog_only($active_signup) {
// get the array of the current user's blogs
$blogs = get_blogs_of_user( get_current_user_id() );
// all users may be members of blog 1 so remove it from the count, could be a "Dashboard" blog as well
if ($blogs["1"]) unset($blogs["1"]);
//if the user still has blogs, disable signup else continue with existing active_signup rules at SiteAdmin->Options
$n = count($blogs);
if($n == 1) {
$active_signup = 'none';
echo '';
} elseif($n > 1) {
$active_signup = 'none';
echo '';
} else {
$active_signup = $active_signup;
}
return $active_signup; // return "all", "none", "blog" or "user"
}
add_filter('wpmu_active_signup', 'ds_one_blog_only');

Then one day while testing some new feature, I discovered that when I register for a sub-site, the sub site first view land on a 404 page. But when I refresh, the sub-site is ok. Initially, I thought it was because I set the New Blog Template 'Make default' feature because that was the last action I did just before I discovered that problem. So I undo the 'Make default' but the problem remained. Then I removed all codes in my functions.php and recreate new sites for new blog templates and do not set default in the New Blog template. Registration of new sites was resumed to normal and working well. However the moment I added the above codes ( the only codes added in function.php), the problem appear --- new sites will first land on a 404 page but will work well when click refresh.

I tried creating my website functionalities on a staging site. I copied over the same functions.php with the above codes to limit one blog per user, I copied the wp-signup.php I replicated all the plugins I have used on my production site and I even set 'Make default' in the New Blog Template, I cannot replicate the 404 problem on the staging site. Registration of new sites and limiting to one blog per user and all other functionalities worked perfectly well on the staging site. Very strange. The only difference between my staging site and my production site is that the production site is using https SSL secure hosting while the staging site does not have a SSL certificate. Could this be the cause? Yet the strange thing is the limit to one blog per user did work well on my production website for quite a long time.

So I removed the above codes and tried the following new codes:

function limit_blog_creation_per_user($active_signup)
{
$blog_limit = 1;
if( !is_super_admin() )
{
$current_user = wp_get_current_user();
$user_blogs = get_blogs_of_user( $current_user->ID );
if (count($user_blogs) >= $blog_limit ) $active_signup = 'none';
}
return $active_signup;
}
add_action('wpmu_active_signup','limit_blog_creation_per_user');

This time, I tested with the first site registration, it works perfectly!! No 404 page. However, when I test a a second site creation, and click on the new site URL to view, it took a long time but finally displayed the new site well. Then I tested a third time, this time, it landed on a 404 page again. Strange!

I hope someone in WPMUDEV team can shed some light to what could be the possible cause of the above problem.

Looking forward to hearing from you!

Esther