WordPress.org

Ready to get started?Download WordPress

Forums

Limiting registered authors to a single category (9 posts)

  1. Anonymous
    Unregistered
    Posted 10 years ago #

    I am developing a WordPress blog for my church to be used to display the monthly vestry meeting minutes, and the monthly letters from each of the clergy. I have looked through the topics, but have not found a hack to limit an author to posting/editing in a single category.
    Has anyone done this?

  2. davidchait
    Member
    Posted 10 years ago #

    Sure. In wp-admin, there's post.php. You want to find the select block that controls the category.

    <select name="cat"...
    ...
    </select >

    You want something like (ignore the {{}}'s...):

    <?php
    $baseUserLevel = {{enter some fixed number here}};
    $defaultCategory = {{your fixed category number here}};
    if ($user_level < $baseUserLevel)
    echo "<input type='hidden' name='cat' value='$defaultCategory' />";
    else
    {
    ?>

    ... the original select name=cat stuff through to the < /select >

    <?php
    }
    ?>

    Something like that should default the category and make it uneditable...
    -d
    http://www.chait.net

  3. Anonymous
    Unregistered
    Posted 10 years ago #

    How would one do this with 1.2Alpha? It seems this has changed since the last stable release.

  4. Anonymous
    Unregistered
    Posted 10 years ago #

    Thanks for the reply, but I find no "<select" upon searching through post.php. There is the following in the xhtml generated by post.php:
    <div>
    <label class="selectit" for="category-1"><input checked="checked" id="category-1" name="post_category[]" type="checkbox" value="2"> Vestry Minutes</label>
    <label class="selectit" for="category-2"><input id="category-2" name="post_category[]" type="checkbox" value="1"> What’s New On Site</label> </div>

    But locating the php code that generated it and being able to alter it is way beyond my capability. I suspect it is in the section that begins with the comment // Insert categories.
    I think I would use the user name rather than user level as each category will have a single user. I suppose most blog sites have no need to restrict a user to posting to or editing only one of many categories, but a church site is likely to have one or two administrators, and several users. For example, I wish to prevent the secretary who does the vestry minutes from posting to or changing the minister's monthly letter. It would be nice to have a function that checked a csv file of users and categories to determine who could do what. Any help would be greatly appreciated.
    -WGH - WordPress 1.0.2 user

  5. Beel
    Member
    Posted 10 years ago #

    *bump* as I am curious as to how this can be done.

  6. davidchait
    Member
    Posted 10 years ago #

    what you're looking for is more than a simple hack. multiple parts of the posting system will need to be modified (i.e., both the new-post and the edit-old-post sections) in order to really, heavily restrict access. Well, I guess you could quickly change editing to only allow the person who originally wrote the message to edit it. Right now, anyone of the same (or greater) user_level can edit a message in the system.
    on the posting side, you'd do much what I said previously, but have to use some kind of table to see what categories a given user can post to. That's getting complex, not something I'd want to write off the cuff (as we'd want a reusable module for people to use, and thus want the WP folks directly involved). you're on the right track, it's just not sitting there as a ready-to-go feature. Of course, the user_level based thing gets you close, but not completely restricting each user.
    you could have a manual table in php that lists a username and the matching category name (which is what I'd put in the database were I creating this for larger consumption... ;) ). then modify my code to keep in the base user level stuff (so that people under some user level are fixed to a SINGLE category, but higher-ups can edit everything), but set the default category variable based on the allowed-cat-table[$user_name] lookup. They'd then automatically get the proper category.
    Looking at the code, it is now 'stored' in two places (AAARGH):
    edit-form-advanced.php AND edit-form.php
    Apparently there's now two variations. You'd want to modify the appropriate one.
    I'll look at edit-form here.... hmmm....
    Looks like the block

    <fieldset id="categorydiv">
    <legend>Categories</legend>
    <div><?php dropdown_categories($default_post_cat); ?></div>
    </fieldset>

    is the new key thing to wrap my above 'if' statement around. It looks like name='post_category[]' (instead of 'cat') is likely what would be needed. I'm not altogether sure what the brackets do in an HTTP post, but as the scripts are presuming the category comes through in a list (even if only one), that might set it up as an automatic array or something.
    As I said (and as this points out), this isn't a small thing, but someone with a chunk of time and a little php knowledge should be able to turn it around.
    -d
    http://www.chait.net

  7. Anonymous
    Unregistered
    Posted 10 years ago #

    d-
    Since we are on the cust of a new version, I guess this will have to
    wait. But I believe it would make WordPress extremely attractive to a much larger group of users.
    Thanks for sharing your knowledge and thoughts about this
    -WGH

  8. Anonymous
    Unregistered
    Posted 10 years ago #

    d-
    Since we are on the cusp of a new version, I guess this will have to
    wait. But I believe it would make WordPress extremely attractive to a much larger group of users.
    Thanks for sharing your knowledge and thoughts about this
    -WGH

  9. Anonymous
    Unregistered
    Posted 9 years ago #

    Was there ever a somewhat simple resolution to this issue? I'm also looking to use WordPress for a community website and have the same needs at the original poster.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.