The MU forums have moved to WordPress.org

How do I limit the number of users in a blog? (7 posts)

  1. pumpkinpatch
    Member
    Posted 16 years ago #

    I want to restrict the number of users (mostly subscribers, one Editor, a few Contributors) in a blog.
    Can it be done?
    Can it be done sitewide?
    Can it be done on a blog-by-blog basis? Like setting the max to 1000 users on one blog, on another 500...

  2. pumpkinpatch
    Member
    Posted 16 years ago #

    bump...

  3. cafespain
    Member
    Posted 16 years ago #

    That's a good one. And I'm not 100% sure how you would accomplish it.

    As far as I can tell from an initial look the users details are held globally (in wp_users) and their access rights for each blog are held in the global wp_usermeta table (on a per user basis).

    For what you want, it would be easier if the information was held the other way around (users for a blog held within the blog data).

    That being said - everything is possible with a little bit of thought and (a lot of) coding.

  4. selad
    Member
    Posted 16 years ago #

    It does not seem to be to much difficult since the code to grab the list of user of a specific blog is out there in wp-admin/users.php.

    If there is a hook when adding a user to a blog one could check the number of users already registered and take action accordingly.

    Much easier said then done:)

  5. dsader
    Member
    Posted 16 years ago #

    Count the total users and remove the addexistinguser form:

    add_filter('show_adduser_fields', 'ds_user_limit');
    function ds_user_limit() {
    $users_of_blog = get_users_of_blog();
    	if (count($users_of_blog) >= 35) {
    	$limit = false;
    	 } else {
    	$limit = true;
    	}
    	return $limit;
    	}

    Limiting what roles are available in the role switcher is a blog option and not a site option (newly created blogs via schema.php).

  6. pumpkinpatch
    Member
    Posted 16 years ago #

    Thanks dsader.
    However, I didn't understand the last sentence:
    "Limiting what roles are available in the role switcher is a blog option and not a site option (newly created blogs via schema.php)"
    Could you please explain?

  7. dsader
    Member
    Posted 16 years ago #

    Certainly, I think the dropdown role switcher in Users is populated by roles defined in wp_BLOGID_user_roles. Each blog may have differing Roles depending on what plugins have ever stored roles there. Having/restoring/controlling a standard set of roles available for blogs site wide would involve writing to this option on every blog, that's all I was figuring.

    In order to limit the number of Editors, on the fly, somehow the dropdown role switcher will have to have the Editor role not appear as a choice if the max number of Editors has been used while at the same time not removing the role from wp_BLOGID_user_roles. This is where I stopped my figuring.

About this Topic

  • Started 16 years ago by pumpkinpatch
  • Latest reply from dsader