WordPress.org

Ready to get started?Download WordPress

Forums

Restrict Categories
Create, manage and use child categories for restricted users (7 posts)

  1. alineo
    Member
    Posted 2 years ago #

    Hi,
    In order to create an intranet, I needed to manage access to the different categories in the site.

    I used Restrict categories (combined with User Role Editor) until I had to face a major problem: restricted users could create a sub category in those they had access to, but only when creating it through a post, and couldn't access it anymore after, couldn't see it in the category manager, and so couldn't add any more post in it.
    The only way would be that administrator manages sub categories which is not to consider.

    So, my main question is: is there a way for restricted users to have a full control of the child categories they need to create in their own categories?

    Continuation of my story. As I had this problem, I tried other plugins and found Advanced access manager, which replaced perfectly both Restrict Categories and User Role Editor, as long as I tested it on my own server. But it refused to work at my clients... So, I switched back to Restrict Categories and User Role Editor, did my categories restrictions by users again (I have about 50 users now, but more will come), SAVED of course, but each time I change the page to manage other users, all the buttons I checked got unchecked...

    As it's an intranet, I can't go at my clients easily, and I did not have enough time to clean the tables yet, so I get this could cause my problem. But I wanted to know anyway if there was something else to suspect...

    Excuse my english (I'm french), hope I'm clear in my explainations...
    And in advance, thanks for any help you could give me.

    http://wordpress.org/extend/plugins/restrict-categories/

  2. alineo
    Member
    Posted 2 years ago #

    Hi,
    as no one answered, and as we were in a little hurry in this project, we went into the plugin's code to make some changes.
    I know it's not a clean way to get what we need, that's why I wanted to show you the code.

    We had, on lines 409 and 428:

    $subcats = get_categories('hierarchical=1&hide_empty=0&child_of='.$term_id);
    foreach ($subcats as $subcat)    {
      $maSousCatID=$subcat->cat_ID;
      $this->cat_list .= $maSousCatID . ',';
    }

    I repeat, the idea was to display sub categories when created by restricted user in his own category.

    Could anyone tell me if there's a nicer way to change the code?

    Thanks.

  3. anou
    Member
    Posted 1 year ago #

    Hello alineo,
    could you be more precise to where to put your lines of code in the original code please ? Maybe if you can give me some of the original code that's before and after your changes ?

    Thanks a lot
    Merci
    David

  4. deanpaddock
    Member
    Posted 1 year ago #


  5. deanpaddock
    Member
    Posted 1 year ago #

    I have used the below code to give me the sub categories of selected categories.
    You add the following code twice:

    $subcats = get_categories('hierarchical=1&hide_empty=0&child_of='.$term_id);
    foreach ($subcats as $subcat)    {
      $this->cat_list .= ($subcat->cat_ID . ',');
    }

    on the next lines after:

    $this->cat_list .= $term_id . ',';

    which are originaly at line numbers 409 and 428.
    So you should have the following code twice:

    $this->cat_list .= $term_id . ',';
    $subcats = get_categories('hierarchical=1&hide_empty=0&child_of='.$term_id);
    foreach ($subcats as $subcat)    {
      $this->cat_list .= ($subcat->cat_ID . ',');
    }

    The extra lines of code obtain the sub categories of the category ($term_id) that the user can view.

  6. alineo
    Member
    Posted 1 year ago #

    Whoa, so much more efficient, cleverly thought.
    Thanks a lot.

    Still we have a problem.
    When a restricted user creates a new sub category, in a post, he can see all the categories until the post is published.
    Of course the new category is checked, as usual, but now the restricted user could also check any other category...

    Any idea about that?

  7. PatJ
    Member
    Posted 1 year ago #

    Thanks for that tweak - it's made the difference between me using the plugin and rejecting it!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic