Limit blogs creation

someone knows how to limit the number of blogs creation in a wordpress multisite? (3.6.1).

In the wordpress plugins repository there is this plugin, but It doesn’t work, I think it’s not up to date.

Read More

Any suggestion would be appreciated, thank you very much.

Related posts

3 comments

  1. The signup page has validation hooks. How about something like this?

    add_filter('wpmu_validate_blog_signup','set_blog_creation_limit');
    
    function set_blog_creation_limit($result) {
    
        $blogs = get_blogs_of_user($result['user']->ID);
    
        if (count($blogs) > 2 )
            $result['errors']->add('blogname', __('You have already registered the maximum amount of blogs!'));
    
        return $result;
    }
    
  2. This is what I’d do.

    Use this add action:

    add_action( 'wpmu_new_blog', 'myFunction' ); 
    
    // parameters $blog_id, $user_id, $domain, $path, $site_id, $meta
    

    And every time a user creates a Blog to check the current blog count get_blog_count() and if it’s less to reverse the action.

    This way you can do an overall limit or limit by user.

  3. Ok, I solved in this manner.
    I can’t say if it’s the best practice, but this solution fit my needs.

    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');
    

    Note: this action doesn’t change the active_signup value stored in the database!

Comments are closed.