0

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.

Any suggestion would be appreciated, thank you very much.

2

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;
}
0

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.

  • It should be add_action(), not do_action(). Also, please provide some detail as to what should be in the myFunction() function. – Pat J Oct 9 '13 at 19:41
0

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.