Limit Number of Blogs per User for wordpress Mu and buddypress website/blog network

Jotted by brajesh on March 25, 2009

Update 28th Feb, 2010: This plugin is updated, Please read more here  http://buddydev.com/buddypress/limit-blogs-per-user-plugin-for-wpmu

Well,It’s a small post after a long time.This time ,I am back with a plugin for wordpress MU.There might have been the times ,when as a site admin of wpmu site, you wished to limit the number of blogs a user can register. My plugin, limitBlogsPU(limit blogs per user),solves this problem.So ,what it does .

  • It adds an option to the options page when you are logged in as site admin of the wpmu site(or wpmu+buddyppress site),Look at the bottom of options page,and You will see a text box like this asking for number of blogs allowed per user.If you set it to zero(which is the default),It will not restrict the blog registration then.
  • It works only,if  you have allowed user registration,otherwise ,this becomes useless if the registration is disabled.
  • When ,a logged in user clicks on register blog (or register another blog,It checks ,whether the current user has already reached the restricted number of blogs),if not then the registration form is shown,otherwise it returns none on filter “wpmu_active_signup” ,restricting the wpmu to not  show registration form.

Who needs this plugin

  • Any wpmu(wordpress Mu)  site owner ,interested in limiting number of blogs registered per user
  • Any Wpmu+buddypress(Social networking plugin) based social network owner,interested in restricting numer of blogs per user.

Where Can you Download

Currently You can download it from my blog here from official wordpress lugin repositoryhttp://downloads.wordpress.org/plugin/limit-blogs-per-user.1.0.zip .

Installation and setup:-

  1. Download the plugin from herehttp://downloads.wordpress.org/plugin/limit-blogs-per-user.1.0.zip
  2. Unzip the plugin and upload the file “limit-bogs-per-user.php“  to your mu-plugins folder.If you have never worked with wpmu before,please read my post WordPress Mu Plugins Installation, sitewide Plugins vs. per blog plugin .
  3. Now The plugin will be automatically activated,please login to the wordpress backend as Site Administrator(site owner)
  4. Go to SiteAdmin-> Options page as show below wpmu options link

Now look at the bottom of options page, you will find something like this Showing The Number of Blogs to restrict fieldThere you will find ,a value 0 initially.Now you may set it to any number.The number indicates,the allowed number of blogs per user. I hope ,It will certainly help some of you.

Please note,it should work with wordpress Mu and Budypress+wpmu both.

Looking forward to your response. Brajesh

[blinklist] [Bloglines] [del.icio.us] [Digg] [dzone] [Facebook] [Ma.gnolia] [Mister Wong] [Reddit] [Sphere] [Sphinn] [StumbleUpon] [Technorati] [Email]
If you enjoyed this post, make sure you subscribe to my RSS feed!
Grab my other free plugins here at wordpress Plugins repository.
We will keep coming with more informative tips,tricks,tutorials to keep you updated with wordpress/buddypress/wordpress mu regularly.If you want to help us,You can ,by spreading the words.We provide free and premium plugins/support for wordpress Mu,buddypress at a very low cost (starting with $30 for 3 months membership).If you or anyone you know,needs some real good plugins/themes for their wordpress Mu/buddypress powered site, Please refer them to http://BuddyDev.com.We will highly appreciate your support and keep coming with more useful and free stuffs.


38 Responses to “Limit Number of Blogs per User for wordpress Mu and buddypress website/blog network”

  1. Andy P says:

    You should add this to the WordPress plugin repo and tag it with “BuddyPress” so it shows up on the BuddyPress website.

    http://wordpress.org/extend/plugins/add/

    • brajesh says:

      hello Andy,It is nice to see you here(btw I am a fan of your work buddypress :) ).Thanks for the suggestions.Certainly ,I will put it there with the tag of buddypress.let us hope it will be there within this week.

      Thanks and with regards
      Brajesh

  2. Kenneth says:

    After trying the plugin it seems that no mather how many blogs I permit, an already registrered user cant create a new blog. If a user, who has no blog but just a username, tries to create blog number 1 he/she gets the ‘Blog creation is closed’-message.

    Setting the number at the options-tab to 10 or 100 doesnt make a difference. Deleting the plugin-file makes it all work again.

    • brajesh says:

      @Kenneth
      Can you point me to your website/blog.I checked again,and found no issues.There should not be any problem with it.I am counting the number of blogs of user using get_blogs_of_user($logged_user_id),So I don’t think,It is causing any problem,If you can point me to your site,may be I can test.
      Thanks
      Brajesh

  3. KaiToU KiD says:

    Thanks, sir..
    I’ll try this plugin ;)

  4. dgodfather says:

    This plugin helps out a lot, however the admins should be not be limited to the number set. I’m sure many would agree that this needs to be adjusted.

  5. dgodfather says:

    Side Note: It appears you have a decent handle on writing plugins like this. You should also make a plugin for buddypress that limits the number of groups allowed.

  6. brajesh says:

    @dgodfather
    I agree with you ,will add the functionality in next release,and thanks for the suggestion,will certainly think about it -:)

  7. Zack says:

    i am using wordpress.org the 2.7.1 version and i can not find the option to limit all authors to 1 blog post.

  8. Zack says:

    so after looking at it, does this plugin allow me to set all “authors” with only 1 post limit, and once they 1 post limit is reached the Add New link on the dashboard is gone?

    Thank You SOOOO MUCH!

  9. Ray says:

    Any update on not restricting site admins?

    • brajesh says:

      hi Ray,thanks for the message.Just next week,I will be releasing the next version,i am going to accommodate all the suggestions then.
      Thanks
      Brajesh

  10. Korhan says:

    There is a problem actually. When user first registers through /register page it seems to work fine when the user signs up for a new blog. If he does not sign up for a blog and decides to sign up later, he will not be allowed to signup later.

    The same problem exists when used with facebook connect plugin. They automatically login using fb-connect and don’t get the chance to sign up for a blog later.

    It should be fixed and also as mentioned before admin should be allowed get unlimited no. blogs.

  11. madLyfe says:

    here is the problem with ur plugin.. if a user decides to register with out creating a blog, he gets assigned as a subscriber to the main sites blog.. well if you only want users to have 1 blog then he cant make one for himself… and if you change the value to 2, then he can make a blog but when he does it remove the main blog subscription and then lets him make another blog of his own..

    • brajesh says:

      hi MadLyfe
      Thanks for pointing the issue.Yeh, you are right about the limitations.The adding to main blog and creating independent blogs are the features handled by wpmu,This plugin simply restricts on number of blogs ,the user is associated with.I will correct it in next release(waiting for wpmu 2.8.3),so It checks for the ownership of blog,not Just the associated blogs.

      Thanks
      Brajesh

  12. madLyfe says:

    can you add a feature to it so it adds a link on the “my blogs” section to create a their blog or another blog depending on the limit set? also the ability to set it so it auto creates the blog as their user name if the limit of blogs is set to one?

  13. Hans says:

    Thank you wery much for this plugin…

    It’s not as good as it could have been due to the problem with subcriber accounts and one blog setting, but i’m looking forward to the update…

    Regards..
    Hans

  14. brajesh says:

    @madLyfe & @Hans
    Thanks for your comments and suggestions.Currently I am a little busy with the work,please wait for a few weeks and we will have an update :)

    Thanks
    Brajesh

  15. jing says:

    this is a good plugin but unfortunately it doesn’t wrk with wordpress mu 2.8
    I have to hard-code the pages limit..

    thanks

  16. deuts says:

    Any update yet on this plugin? Would love to see this plugin through.

  17. Just tested, it works fine on WPMU-2.8.5.2.

    Cheers!

    • If you change to this, admin and other bug will be fixed. Thank for the effort!


      /**** Check, whether blog registration is allowed,and how many blogs per logged in user is allowed ****/

      function tiw_check_current_users_blog ($active_signup)
      {
      if ( !is_user_logged_in() )
      return $active_signup; // if the user is not logged in, do not change the site policies

      //otherwise...
      $number_of_blogs_per_user = tiw_num_allowed_blogs (); // find
      if (0 == $number_of_blogs_per_user) {
      return $active_signup;
      }

      global $current_user;
      $blogs = get_blogs_of_user($current_user->ID); // get all blogs of user

      //if number of allowed blog is greater than 0 and current user owns less number of blogs */
      if ( ($number_of_blogs_per_user>0) && (count($blogs)<$number_of_blogs_per_user) ) {
      return $active_signup;
      } else {
      return "none";
      }
      }

      /**** How many blogs are allowed per user ****/

      function tiw_num_allowed_blogs ()
      {
      $num_allowed_blog = get_site_option ("tiw_allowed_blogs_per_user"); // find how many blogs are allowed
      if ( (!isset($num_allowed_blog)) || is_site_admin() ) {
      $num_allowed_blog = 0;
      }
      return $num_allowed_blog; // return the number of allowed blogs
      }

  18. Steph says:

    I was able to get this working well with this code at line 16:

    function tiw_check_current_users_blog($active_signup)
    {
    if( !is_user_logged_in() || is_site_admin())
    return $active_signup;//if the user is not logged in,do not change the site policies

    //otherwise…
    global $current_user, $wpdb;
    $blogs=get_blogs_of_user($current_user->ID);//get all blogs of user

    foreach($blogs as $key => $blog){
    $cap_key = $wpdb->base_prefix . $blog->userblog_id . ‘_capabilities’;

    if ( $blog->userblog_id == 1 || (is_array($current_user->$cap_key) && in_array(‘subscriber’, $current_user->$cap_key)) )
    unset($blogs[$key]);
    }

    $number_of_blogs_per_user=tiw_num_allowed_blogs();//find

    //if number of allowed blog is greater than 0 and current user owns less number of blogs */
    if($number_of_blogs_per_user>0 && count($blogs)<$number_of_blogs_per_user)
    return $active_signup;
    else
    return "none";
    }

  19. Steph says:

    err… That actually doesn’t work right. The line:

    needs to be changed to:

    if ( $blog->userblog_id == 1 || (is_array($current_user->$cap_key) && !in_array(‘administrator’, $current_user->$cap_key)) )

    This code excludes the main blog from the count an any blogs where the user is not an admin.

  20. brajesh says:

    @deuts
    Thanks for visiting.There will be an update available by 9th Nov.
    @Steph ,@Brand and Gingles
    Thanks for your improvements.I have to test the updated version and I will quote you both(if your solution worked best :) ) on the new update of plugin :)

    Thanks for all the suggestions and code snippets.

  21. Kin says:

    Hi,

    I would please like to ask if this plug-in should work with the standard wordpress installation? (not MU). I am currently using wordpress 2.8.5. I am quite new to wordpress and I don’t use it frequently.

    Also, after installing it with the wp version that I have, I can’t seem to find the input fields whihc would allow me to set the limit of posts for certain users.

    Thank you very much for any help you may provide and more power to you!

  22. Steph says:

    Thanks for the update. Looks like you missed adding:
    global $wpdb; in the tiw_check_current_users_blog function.

    Thanks again!

    • brajesh says:

      Thanks Steph for pointing the bug again.
      Though There seems to be some other issues too.I have just reverted the stable tag to 1.0 and now Hopefully tomorrow will have a fully working plugin :) thanks for all your help

  23. PEN 2 NET says:

    I am already using this plugin on my blog and it works just fine. Great idea and nice work :)

  24. Hei… really nice plugin here! Thanks!

  25. Mark says:

    Hi Brajesh,

    Great Plugin. Will this work with wordpress mu 2.8.6 and buddypress 1.1.3?

    • brajesh says:

      Yes, It will work, but there is a glitch as pointed above, if you set the number of blogs to 1, it will not allow a subscriber to create a new blog.
      I am looking forward to update this plugin after 15th feb to fix that 1 blog issue with subscriber.
      Thanks
      Brajesh

  26. Ecenica says:

    Adding our name to the list so that we can be updated when the new plugin is available. Looking forward to it!

  27. [...] So, here goes the post about this. If you are wondering about this plugin, you may like to check it on my other blog here [...]

  28. brajesh says:

    hi all, I have updated this plugin.
    You may read more here
    http://buddydev.com/buddypress/limit-blogs-per-user-plugin-for-wpmu

    I am leaving a comment here, so you all will get notify of the updates(If subscribed to the comments :) )

    Thanks
    Brajesh


Leave a Reply


Get Adobe Flash playerPlugin by wpburn.com wordpress themes